@loopback/example-lb3-application 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +2 -0
- package/.prettierrc +7 -0
- package/.vscode/settings.json +20 -0
- package/.vscode/tasks.json +29 -0
- package/CHANGELOG.md +626 -0
- package/LICENSE +25 -0
- package/README.md +560 -0
- package/dist/__tests__/acceptance/home-page.acceptance.d.ts +1 -0
- package/dist/__tests__/acceptance/home-page.acceptance.js +38 -0
- package/dist/__tests__/acceptance/home-page.acceptance.js.map +1 -0
- package/dist/__tests__/acceptance/lb3app.acceptance.d.ts +1 -0
- package/dist/__tests__/acceptance/lb3app.acceptance.js +200 -0
- package/dist/__tests__/acceptance/lb3app.acceptance.js.map +1 -0
- package/dist/__tests__/acceptance/test-helper.d.ts +11 -0
- package/dist/__tests__/acceptance/test-helper.js +33 -0
- package/dist/__tests__/acceptance/test-helper.js.map +1 -0
- package/dist/application.d.ts +187 -0
- package/dist/application.js +41 -0
- package/dist/application.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate.d.ts +1 -0
- package/dist/migrate.js +25 -0
- package/dist/migrate.js.map +1 -0
- package/dist/openapi-spec.d.ts +1 -0
- package/dist/openapi-spec.js +28 -0
- package/dist/openapi-spec.js.map +1 -0
- package/dist/sequence.d.ts +3 -0
- package/dist/sequence.js +12 -0
- package/dist/sequence.js.map +1 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +58 -0
- package/dist/server.js.map +1 -0
- package/lb3app/common/models/coffee-shop.js +44 -0
- package/lb3app/common/models/coffee-shop.json +30 -0
- package/lb3app/server/boot/authentication.js +11 -0
- package/lb3app/server/boot/create-sample-models.js +28 -0
- package/lb3app/server/config.json +21 -0
- package/lb3app/server/datasources.json +6 -0
- package/lb3app/server/middleware.json +9 -0
- package/lb3app/server/model-config.json +39 -0
- package/lb3app/server/server.js +17 -0
- package/lb3app/test/acceptance.js +107 -0
- package/lb3app/test/authentication.js +135 -0
- package/lb3app/test/integration.js +75 -0
- package/package.json +78 -0
- package/public/index.html +74 -0
- package/public/lb3-index.html +5 -0
- package/src/__tests__/acceptance/home-page.acceptance.ts +44 -0
- package/src/__tests__/acceptance/lb3app.acceptance.ts +244 -0
- package/src/__tests__/acceptance/test-helper.ts +40 -0
- package/src/application.ts +44 -0
- package/src/index.ts +35 -0
- package/src/migrate.ts +25 -0
- package/src/openapi-spec.ts +28 -0
- package/src/sequence.ts +8 -0
- package/src/server.ts +71 -0
- package/tsconfig.json +36 -0
package/src/sequence.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2019. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/example-lb3-application
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {MiddlewareSequence} from '@loopback/rest';
|
|
7
|
+
|
|
8
|
+
export class MySequence extends MiddlewareSequence {}
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/example-lb3-application
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {ApplicationConfig} from '@loopback/core';
|
|
7
|
+
import {once} from 'events';
|
|
8
|
+
import express, {Request, Response} from 'express';
|
|
9
|
+
import http from 'http';
|
|
10
|
+
import {AddressInfo} from 'net';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import {CoffeeShopApplication} from './application';
|
|
13
|
+
|
|
14
|
+
const loopback = require('loopback');
|
|
15
|
+
const compression = require('compression');
|
|
16
|
+
const cors = require('cors');
|
|
17
|
+
const helmet = require('helmet');
|
|
18
|
+
|
|
19
|
+
export {ApplicationConfig};
|
|
20
|
+
|
|
21
|
+
export class ExpressServer {
|
|
22
|
+
private app: express.Application;
|
|
23
|
+
public readonly lbApp: CoffeeShopApplication;
|
|
24
|
+
public server?: http.Server;
|
|
25
|
+
public url: String;
|
|
26
|
+
|
|
27
|
+
constructor(options: ApplicationConfig = {}) {
|
|
28
|
+
this.app = express();
|
|
29
|
+
|
|
30
|
+
this.lbApp = new CoffeeShopApplication(options);
|
|
31
|
+
|
|
32
|
+
// Middleware migrated from LoopBack 3
|
|
33
|
+
this.app.use(loopback.favicon());
|
|
34
|
+
this.app.use(compression());
|
|
35
|
+
this.app.use(cors());
|
|
36
|
+
this.app.use(helmet());
|
|
37
|
+
|
|
38
|
+
// Mount the LB4 REST API
|
|
39
|
+
this.app.use('/api', this.lbApp.requestHandler);
|
|
40
|
+
|
|
41
|
+
// Custom Express routes
|
|
42
|
+
this.app.get('/ping', function (_req: Request, res: Response) {
|
|
43
|
+
res.send('pong');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Serve static files in the public folder
|
|
47
|
+
this.app.use(express.static(path.join(__dirname, '../public')));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async boot() {
|
|
51
|
+
await this.lbApp.boot();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public async start() {
|
|
55
|
+
await this.lbApp.start();
|
|
56
|
+
const port = this.lbApp.restServer.config.port ?? 3000;
|
|
57
|
+
const host = this.lbApp.restServer.config.host ?? '127.0.0.1';
|
|
58
|
+
this.server = this.app.listen(port, host);
|
|
59
|
+
await once(this.server, 'listening');
|
|
60
|
+
const add = <AddressInfo>this.server.address();
|
|
61
|
+
this.url = `http://${add.address}:${add.port}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public async stop() {
|
|
65
|
+
if (!this.server) return;
|
|
66
|
+
await this.lbApp.stop();
|
|
67
|
+
this.server.close();
|
|
68
|
+
await once(this.server, 'close');
|
|
69
|
+
this.server = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "@loopback/build/config/tsconfig.common.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"composite": true
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"src/**/*",
|
|
11
|
+
"src/**/*.json"
|
|
12
|
+
],
|
|
13
|
+
"references": [
|
|
14
|
+
{
|
|
15
|
+
"path": "../../packages/boot/tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../../packages/booter-lb3app/tsconfig.json"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "../../packages/core/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../packages/repository/tsconfig.json"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../../packages/rest-explorer/tsconfig.json"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "../../packages/rest/tsconfig.json"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "../../packages/testlab/tsconfig.json"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|