Skip to content

Commit

Permalink
feat: add booter-lb3app package
Browse files Browse the repository at this point in the history
Co-authored-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
nabdelgadir and bajtos committed Apr 24, 2019
1 parent 469830f commit c122fd5
Show file tree
Hide file tree
Showing 33 changed files with 3,483 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

packages/authentication/* @bajtos @raymondfeng
packages/boot/* @raymondfeng @hacksparrow
packages/booter-lb3app/* @bajtos @nabdelgadir
packages/build/* @bajtos @raymondfeng
packages/http-caching-proxy/* @bajtos
packages/http-server/* @hacksparrow @bajtos
Expand Down
1 change: 1 addition & 0 deletions docs/apidocs.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h3>List of packages</h3>
<ul>
<li><a href="./authentication.html">@loopback/authentication</a></li>
<li><a href="./boot.html">@loopback/boot</a></li>
<li><a href="./booter-lb3app.html">@loopback/booter-lb3app</a></li>
<li><a href="./context.html">@loopback/context</a></li>
<li><a href="./core.html">@loopback/core</a></li>
<li><a href="./http-caching-proxy.html">@loopback/http-caching-proxy</a></li>
Expand Down
10 changes: 10 additions & 0 deletions docs/site/Boot-and-Mount-a-LoopBack-3-application.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
lang: en
title: 'Boot and Mount a LoopBack 3 Application'
keywords: LoopBack 4.0, LoopBack 4, LoopBack 3
layout: readme
source: loopback-next
file: packages/booter-lb3app/README.md
sidebar: lb4_sidebar
permalink: /doc/en/lb4/Boot-and-Mount-a-LoopBack-3-application.html
---
1 change: 1 addition & 0 deletions docs/site/MONOREPO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The [loopback-next](https://github.com/strongloop/loopback-next) repository uses
| Package | npm | Description |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [authentication](https://github.com/strongloop/loopback-next/tree/master/packages/authentication) | @loopback/authentication | A component for authentication support |
| [booter-lb3app](https://github.com/strongloop/loopback-next/tree/master/packages/booter-lb3app) | @loopback/booter-lb3app | A booter component for LoopBack 3 applications to expose their REST API via LoopBack 4. |
| [boot](https://github.com/strongloop/loopback-next/tree/master/packages/boot) | @loopback/boot | Convention based Bootstrapper and Booters |
| [build](https://github.com/strongloop/loopback-next/tree/master/packages/build) | @loopback/build | A set of common scripts and default configurations to build LoopBack 4 or other TypeScript modules |
| [cli](https://github.com/strongloop/loopback-next/tree/master/packages/cli) | @loopback/cli | CLI for LoopBack 4 |
Expand Down
4 changes: 4 additions & 0 deletions docs/site/sidebars/lb4_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ children:
url: Loopback-component-authorization.html
output: 'web, pdf'

- title: 'Boot and Mount a LoopBack 3 Application'
url: Boot-and-Mount-a-LoopBack-3-application.html
output: 'web, pdf'

- title: 'Calling other APIs'
url: Calling-other-APIs-and-web-services.html
output: 'web, pdf'
Expand Down
1 change: 1 addition & 0 deletions greenkeeper.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"examples/todo/package.json",
"packages/authentication/package.json",
"packages/boot/package.json",
"packages/booter-lb3app/package.json",
"packages/build/package.json",
"packages/cli/package.json",
"packages/context/package.json",
Expand Down
1 change: 1 addition & 0 deletions packages/booter-lb3app/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=true
4 changes: 4 additions & 0 deletions packages/booter-lb3app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
25 changes: 25 additions & 0 deletions packages/booter-lb3app/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) IBM Corp. 2019. All Rights Reserved.
Node module: @loopback/booter-lb3app
This project is licensed under the MIT License, full text below.

--------

MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
48 changes: 48 additions & 0 deletions packages/booter-lb3app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# @loopback/booter-lb3app

Boot a LoopBack 3 application and expose its REST API via LoopBack 4.

## Overview

The `@loopback/booter-lb3app` package provides a way for LoopBack 3 developers
to boot their LoopBack 3 application, convert the application's Swagger spec
into OpenAPI v3, and then mount the application, including its spec, onto a
target LoopBack 4 application.

## Installation

```sh
npm install --save @loopback/booter-lb3app
```

## Basic use

Import the component at the top of your `src/application.ts` file.

```ts
import {Lb3AppBooterComponent} from '@loopback/booter-lb3app';
```

Register the component in Application's constructor:

```ts
this.component(Lb3AppBooterComponent);
```

## Contributions

- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)

## Tests

Run `npm test` from the root folder.

## Contributors

See
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).

## License

MIT
7 changes: 7 additions & 0 deletions packages/booter-lb3app/docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"content": [
"src/lb3app.booter.ts",
"src/lb3app.booter.component.ts"
],
"codeSectionDepth": 4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

module.exports = function(CoffeeShop) {
CoffeeShop.status = function(cb) {
var currentDate = new Date();
var currentHour = currentDate.getHours();
var OPEN_HOUR = 6;
var CLOSE_HOUR = 20;

var response;
if (currentHour >= OPEN_HOUR && currentHour < CLOSE_HOUR) {
response = 'We are open for business.';
} else {
response = 'Sorry, we are closed. Open daily from 6am to 8pm.';
}
cb(null, response);
};
CoffeeShop.remoteMethod('status', {
http: {
path: '/status',
verb: 'get',
},
returns: {
arg: 'status',
type: 'string',
},
});
CoffeeShop.getName = function(shopId, cb) {
CoffeeShop.findById(shopId, function(err, instance) {
var response = 'Name of coffee shop is ' + instance.name;
cb(null, response);
});
};
CoffeeShop.remoteMethod('getName', {
http: {path: '/getname', verb: 'get'},
accepts: {
arg: 'id',
type: 'number',
required: true,
http: {source: 'query'},
},
returns: {arg: 'name', type: 'string'},
});
CoffeeShop.greet = function(cb) {
process.nextTick(function() {
cb(null, 'Hello from this Coffee Shop');
});
};
CoffeeShop.remoteMethod('greet', {
http: {path: '/greet', verb: 'get'},
returns: {type: 'string'},
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name":"CoffeeShop",
"base":"PersistedModel",
"idInjection":true,
"options":{
"validateUpsert":true
},
"properties":{
"name":{
"type":"string",
"required":true
},
"city":{
"type":"string",
"required":true
}
},
"validations":[],
"relations":{},
"acls":[
{
"accessType":"EXECUTE",
"principalType":"ROLE",
"principalId":"$unauthenticated",
"permission":"DENY",
"property":"greet"
}
],
"methods":{}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = function enableAuthentication(server) {
// enable authentication
server.enableAuth();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

module.exports = function(app) {
app.dataSources.db.automigrate('CoffeeShop', function(err) {
if (err) throw err;

app.models.CoffeeShop.create(
[
{
name: 'Bel Cafe',
city: 'Vancouver',
},
{
name: 'Three Bees Coffee House',
city: 'San Mateo',
},
{
name: 'Caffe Artigiano',
city: 'Vancouver',
},
],
function(err, coffeeShops) {
if (err) throw err;
},
);
});
};
6 changes: 6 additions & 0 deletions packages/booter-lb3app/fixtures/lb3app/server/boot/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function(app) {
// Install a "/ping" route that returns "pong"
app.get('/ping', function(req, res) {
res.send('pong');
});
};
22 changes: 22 additions & 0 deletions packages/booter-lb3app/fixtures/lb3app/server/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"restApiRoot":"/api",
"host":"0.0.0.0",
"port":3000,
"remoting":{
"context":false,
"rest":{
"handleErrors":false,
"normalizeHttpPath":false,
"xml":false
},
"json":{
"strict":false,
"limit":"100kb"
},
"urlencoded":{
"extended":true,
"limit":"100kb"
},
"cors":false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"db":{
"name": "db",
"connector": "memory"
}
}
46 changes: 46 additions & 0 deletions packages/booter-lb3app/fixtures/lb3app/server/middleware.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"initial:before": {
"loopback#favicon": {}
},
"initial": {
"compression": {},
"cors": {
"params": {
"origin": true,
"credentials": true,
"maxAge": 86400
}
},
"helmet#xssFilter": {},
"helmet#frameguard": {
"params": [
"deny"
]
},
"helmet#hsts": {
"params": {
"maxAge": 0,
"includeSubDomains": true
}
},
"helmet#hidePoweredBy": {},
"helmet#ieNoOpen": {},
"helmet#noSniff": {},
"helmet#noCache": {
"enabled": false
}
},
"session": {},
"auth": {},
"parse": {},
"routes": {
"loopback#rest": {
"paths": [
"${restApiRoot}"
]
}
},
"files": {},
"final": {},
"final:after": {}
}
42 changes: 42 additions & 0 deletions packages/booter-lb3app/fixtures/lb3app/server/model-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"_meta":{
"sources":[
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins":[
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins"
]
},
"User":{
"dataSource":"db"
},
"AccessToken":{
"dataSource":"db",
"public":false
},
"ACL":{
"dataSource":"db",
"public":false
},
"RoleMapping":{
"dataSource":"db",
"public":false,
"options":{
"strictObjectIDCoercion":true
}
},
"Role":{
"dataSource":"db",
"public":false
},
"CoffeeShop":{
"dataSource":"db",
"public":true
}
}
Loading

0 comments on commit c122fd5

Please sign in to comment.