@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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/example-lb3-application
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CoffeeShopApplication = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const boot_1 = require("@loopback/boot");
|
|
10
|
+
const booter_lb3app_1 = require("@loopback/booter-lb3app");
|
|
11
|
+
const repository_1 = require("@loopback/repository");
|
|
12
|
+
const rest_1 = require("@loopback/rest");
|
|
13
|
+
const rest_explorer_1 = require("@loopback/rest-explorer");
|
|
14
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
15
|
+
const sequence_1 = require("./sequence");
|
|
16
|
+
class CoffeeShopApplication extends boot_1.BootMixin(repository_1.RepositoryMixin(rest_1.RestApplication)) {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
super(options);
|
|
19
|
+
// Set up the custom sequence
|
|
20
|
+
this.sequence(sequence_1.MySequence);
|
|
21
|
+
// Set up default home page
|
|
22
|
+
this.static('/', path_1.default.join(__dirname, '../public'));
|
|
23
|
+
this.component(rest_explorer_1.RestExplorerComponent);
|
|
24
|
+
this.component(booter_lb3app_1.Lb3AppBooterComponent);
|
|
25
|
+
this.projectRoot = __dirname;
|
|
26
|
+
// Customize @loopback/boot Booter Conventions here
|
|
27
|
+
this.bootOptions = {
|
|
28
|
+
controllers: {
|
|
29
|
+
// Customize ControllerBooter Conventions here
|
|
30
|
+
dirs: ['controllers'],
|
|
31
|
+
extensions: ['.controller.js'],
|
|
32
|
+
nested: true,
|
|
33
|
+
},
|
|
34
|
+
lb3app: {
|
|
35
|
+
mode: 'fullApp',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.CoffeeShopApplication = CoffeeShopApplication;
|
|
41
|
+
//# sourceMappingURL=application.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iDAAiD;AACjD,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAAyC;AACzC,2DAA8D;AAE9D,qDAAqD;AACrD,yCAA+C;AAC/C,2DAA8D;AAC9D,wDAAwB;AACxB,yCAAsC;AAEtC,MAAa,qBAAsB,SAAQ,gBAAS,CAClD,4BAAe,CAAC,sBAAe,CAAC,CACjC;IACC,YAAY,UAA6B,EAAE;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,6BAA6B;QAC7B,IAAI,CAAC,QAAQ,CAAC,qBAAU,CAAC,CAAC;QAE1B,2BAA2B;QAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;QAEpD,IAAI,CAAC,SAAS,CAAC,qCAAqB,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,CAAC,qCAAqB,CAAC,CAAC;QAEtC,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC7B,mDAAmD;QACnD,IAAI,CAAC,WAAW,GAAG;YACjB,WAAW,EAAE;gBACX,8CAA8C;gBAC9C,IAAI,EAAE,CAAC,aAAa,CAAC;gBACrB,UAAU,EAAE,CAAC,gBAAgB,CAAC;gBAC9B,MAAM,EAAE,IAAI;aACb;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;aAChB;SACF,CAAC;IACJ,CAAC;CACF;AA7BD,sDA6BC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/example-lb3-application
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
var _a, _b;
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.main = void 0;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const server_1 = require("./server");
|
|
11
|
+
tslib_1.__exportStar(require("./server"), exports);
|
|
12
|
+
async function main(options = {}) {
|
|
13
|
+
const server = new server_1.ExpressServer(options);
|
|
14
|
+
await server.boot();
|
|
15
|
+
await server.start();
|
|
16
|
+
console.log(`Server is running at ${server.url}`);
|
|
17
|
+
}
|
|
18
|
+
exports.main = main;
|
|
19
|
+
if (require.main === module) {
|
|
20
|
+
// Run the application
|
|
21
|
+
const config = {
|
|
22
|
+
rest: {
|
|
23
|
+
port: +((_a = process.env.PORT) !== null && _a !== void 0 ? _a : 3000),
|
|
24
|
+
host: (_b = process.env.HOST) !== null && _b !== void 0 ? _b : 'localhost',
|
|
25
|
+
openApiSpec: {
|
|
26
|
+
// useful when used with OpenAPI-to-GraphQL to locate your application
|
|
27
|
+
setServersFromRequest: true,
|
|
28
|
+
},
|
|
29
|
+
// Use the LB4 application as a route. It should not be listening.
|
|
30
|
+
listenOnStart: false,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
main(config).catch(err => {
|
|
34
|
+
console.error('Cannot start the application.', err);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iDAAiD;AACjD,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,qCAA0D;AAE1D,mDAAyB;AAElB,KAAK,UAAU,IAAI,CAAC,UAA6B,EAAE;IACxD,MAAM,MAAM,GAAG,IAAI,sBAAa,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;IACpB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,wBAAwB,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;AACpD,CAAC;AALD,oBAKC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;IAC3B,sBAAsB;IACtB,MAAM,MAAM,GAAG;QACb,IAAI,EAAE;YACJ,IAAI,EAAE,CAAC,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,IAAI,mCAAI,IAAI,CAAC;YACjC,IAAI,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,IAAI,mCAAI,WAAW;YACrC,WAAW,EAAE;gBACX,sEAAsE;gBACtE,qBAAqB,EAAE,IAAI;aAC5B;YACD,kEAAkE;YAClE,aAAa,EAAE,KAAK;SACrB;KACF,CAAC;IACF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function migrate(args: string[]): Promise<void>;
|
package/dist/migrate.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/example-lb3-application
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.migrate = void 0;
|
|
8
|
+
const server_1 = require("./server");
|
|
9
|
+
async function migrate(args) {
|
|
10
|
+
const existingSchema = args.includes('--rebuild') ? 'drop' : 'alter';
|
|
11
|
+
console.log('Migrating schemas (%s existing schema)', existingSchema);
|
|
12
|
+
const server = new server_1.ExpressServer();
|
|
13
|
+
await server.boot();
|
|
14
|
+
await server.lbApp.migrateSchema({ existingSchema });
|
|
15
|
+
// Connectors usually keep a pool of opened connections,
|
|
16
|
+
// this keeps the process running even after all work is done.
|
|
17
|
+
// We need to exit explicitly.
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
exports.migrate = migrate;
|
|
21
|
+
migrate(process.argv).catch(err => {
|
|
22
|
+
console.error('Cannot migrate database schema', err);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iDAAiD;AACjD,+CAA+C;AAC/C,gEAAgE;;;AAEhE,qCAAuC;AAEhC,KAAK,UAAU,OAAO,CAAC,IAAc;IAC1C,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IACrE,OAAO,CAAC,GAAG,CAAC,wCAAwC,EAAE,cAAc,CAAC,CAAC;IAEtE,MAAM,MAAM,GAAG,IAAI,sBAAa,EAAE,CAAC;IACnC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;IACpB,MAAM,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAC,cAAc,EAAC,CAAC,CAAC;IAEnD,wDAAwD;IACxD,8DAA8D;IAC9D,8BAA8B;IAC9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAZD,0BAYC;AAED,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;IAChC,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;IACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/example-lb3-application
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const application_1 = require("./application");
|
|
8
|
+
/**
|
|
9
|
+
* Export the OpenAPI spec from the application
|
|
10
|
+
*/
|
|
11
|
+
async function exportOpenApiSpec() {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
const config = {
|
|
14
|
+
rest: {
|
|
15
|
+
port: +((_a = process.env.PORT) !== null && _a !== void 0 ? _a : 3000),
|
|
16
|
+
host: (_b = process.env.HOST) !== null && _b !== void 0 ? _b : 'localhost',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const outFile = (_c = process.argv[2]) !== null && _c !== void 0 ? _c : '';
|
|
20
|
+
const app = new application_1.CoffeeShopApplication(config);
|
|
21
|
+
await app.boot();
|
|
22
|
+
await app.exportOpenApiSpec(outFile);
|
|
23
|
+
}
|
|
24
|
+
exportOpenApiSpec().catch(err => {
|
|
25
|
+
console.error('Fail to export OpenAPI spec from the application.', err);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=openapi-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-spec.js","sourceRoot":"","sources":["../src/openapi-spec.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iDAAiD;AACjD,+CAA+C;AAC/C,gEAAgE;;AAGhE,+CAAoD;AAEpD;;GAEG;AACH,KAAK,UAAU,iBAAiB;;IAC9B,MAAM,MAAM,GAAsB;QAChC,IAAI,EAAE;YACJ,IAAI,EAAE,CAAC,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,IAAI,mCAAI,IAAI,CAAC;YACjC,IAAI,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,IAAI,mCAAI,WAAW;SACtC;KACF,CAAC;IACF,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,mCAAI,EAAE,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,mCAAqB,CAAC,MAAM,CAAC,CAAC;IAC9C,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACjB,MAAM,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC;AAED,iBAAiB,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;IAC9B,OAAO,CAAC,KAAK,CAAC,mDAAmD,EAAE,GAAG,CAAC,CAAC;IACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/sequence.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/example-lb3-application
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.MySequence = void 0;
|
|
8
|
+
const rest_1 = require("@loopback/rest");
|
|
9
|
+
class MySequence extends rest_1.MiddlewareSequence {
|
|
10
|
+
}
|
|
11
|
+
exports.MySequence = MySequence;
|
|
12
|
+
//# sourceMappingURL=sequence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iDAAiD;AACjD,+CAA+C;AAC/C,gEAAgE;;;AAEhE,yCAAkD;AAElD,MAAa,UAAW,SAAQ,yBAAkB;CAAG;AAArD,gCAAqD"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ApplicationConfig } from '@loopback/core';
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import { CoffeeShopApplication } from './application';
|
|
5
|
+
export { ApplicationConfig };
|
|
6
|
+
export declare class ExpressServer {
|
|
7
|
+
private app;
|
|
8
|
+
readonly lbApp: CoffeeShopApplication;
|
|
9
|
+
server?: http.Server;
|
|
10
|
+
url: String;
|
|
11
|
+
constructor(options?: ApplicationConfig);
|
|
12
|
+
boot(): Promise<void>;
|
|
13
|
+
start(): Promise<void>;
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/example-lb3-application
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ExpressServer = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const events_1 = require("events");
|
|
10
|
+
const express_1 = tslib_1.__importDefault(require("express"));
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const application_1 = require("./application");
|
|
13
|
+
const loopback = require('loopback');
|
|
14
|
+
const compression = require('compression');
|
|
15
|
+
const cors = require('cors');
|
|
16
|
+
const helmet = require('helmet');
|
|
17
|
+
class ExpressServer {
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
this.app = express_1.default();
|
|
20
|
+
this.lbApp = new application_1.CoffeeShopApplication(options);
|
|
21
|
+
// Middleware migrated from LoopBack 3
|
|
22
|
+
this.app.use(loopback.favicon());
|
|
23
|
+
this.app.use(compression());
|
|
24
|
+
this.app.use(cors());
|
|
25
|
+
this.app.use(helmet());
|
|
26
|
+
// Mount the LB4 REST API
|
|
27
|
+
this.app.use('/api', this.lbApp.requestHandler);
|
|
28
|
+
// Custom Express routes
|
|
29
|
+
this.app.get('/ping', function (_req, res) {
|
|
30
|
+
res.send('pong');
|
|
31
|
+
});
|
|
32
|
+
// Serve static files in the public folder
|
|
33
|
+
this.app.use(express_1.default.static(path_1.default.join(__dirname, '../public')));
|
|
34
|
+
}
|
|
35
|
+
async boot() {
|
|
36
|
+
await this.lbApp.boot();
|
|
37
|
+
}
|
|
38
|
+
async start() {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
await this.lbApp.start();
|
|
41
|
+
const port = (_a = this.lbApp.restServer.config.port) !== null && _a !== void 0 ? _a : 3000;
|
|
42
|
+
const host = (_b = this.lbApp.restServer.config.host) !== null && _b !== void 0 ? _b : '127.0.0.1';
|
|
43
|
+
this.server = this.app.listen(port, host);
|
|
44
|
+
await events_1.once(this.server, 'listening');
|
|
45
|
+
const add = this.server.address();
|
|
46
|
+
this.url = `http://${add.address}:${add.port}`;
|
|
47
|
+
}
|
|
48
|
+
async stop() {
|
|
49
|
+
if (!this.server)
|
|
50
|
+
return;
|
|
51
|
+
await this.lbApp.stop();
|
|
52
|
+
this.server.close();
|
|
53
|
+
await events_1.once(this.server, 'close');
|
|
54
|
+
this.server = undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.ExpressServer = ExpressServer;
|
|
58
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iDAAiD;AACjD,+CAA+C;AAC/C,gEAAgE;;;;AAGhE,mCAA4B;AAC5B,8DAAmD;AAGnD,wDAAwB;AACxB,+CAAoD;AAEpD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACrC,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAIjC,MAAa,aAAa;IAMxB,YAAY,UAA6B,EAAE;QACzC,IAAI,CAAC,GAAG,GAAG,iBAAO,EAAE,CAAC;QAErB,IAAI,CAAC,KAAK,GAAG,IAAI,mCAAqB,CAAC,OAAO,CAAC,CAAC;QAEhD,sCAAsC;QACtC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAEvB,yBAAyB;QACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAEhD,wBAAwB;QACxB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,IAAa,EAAE,GAAa;YAC1D,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;QAEH,0CAA0C;QAC1C,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,MAAM,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,KAAK;;QAChB,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,mCAAI,IAAI,CAAC;QACvD,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,mCAAI,WAAW,CAAC;QAC9D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC1C,MAAM,aAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACrC,MAAM,GAAG,GAAgB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC/C,IAAI,CAAC,GAAG,GAAG,UAAU,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;IACjD,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO;QACzB,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,MAAM,aAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;CACF;AAlDD,sCAkDC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const debug = require('debug')('loopback:example:lb3application');
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
+
module.exports = function (CoffeeShop) {
|
|
12
|
+
CoffeeShop.status = async function () {
|
|
13
|
+
const currentDate = new Date();
|
|
14
|
+
const currentHour = currentDate.getHours();
|
|
15
|
+
const OPEN_HOUR = 6;
|
|
16
|
+
const CLOSE_HOUR = 20;
|
|
17
|
+
debug('Current hour is %d', currentHour);
|
|
18
|
+
let response;
|
|
19
|
+
if (currentHour > OPEN_HOUR && currentHour < CLOSE_HOUR) {
|
|
20
|
+
response = 'We are open for business.';
|
|
21
|
+
} else {
|
|
22
|
+
response = 'Sorry, we are closed. Open daily from 6am to 8pm.';
|
|
23
|
+
}
|
|
24
|
+
return response;
|
|
25
|
+
};
|
|
26
|
+
CoffeeShop.remoteMethod('status', {
|
|
27
|
+
http: {
|
|
28
|
+
path: '/status',
|
|
29
|
+
verb: 'get',
|
|
30
|
+
},
|
|
31
|
+
returns: {
|
|
32
|
+
arg: 'status',
|
|
33
|
+
type: 'string',
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
CoffeeShop.greet = async function () {
|
|
38
|
+
return 'Hello from this Coffee Shop';
|
|
39
|
+
};
|
|
40
|
+
CoffeeShop.remoteMethod('greet', {
|
|
41
|
+
http: {path: '/greet', verb: 'get'},
|
|
42
|
+
returns: {arg: 'greeting', type: 'string'},
|
|
43
|
+
});
|
|
44
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "CoffeeShop",
|
|
3
|
+
"base": "PersistedModel",
|
|
4
|
+
"idInjection": true,
|
|
5
|
+
"forceId": false,
|
|
6
|
+
"options": {
|
|
7
|
+
"validateUpsert": true
|
|
8
|
+
},
|
|
9
|
+
"properties": {
|
|
10
|
+
"name": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"required": true
|
|
13
|
+
},
|
|
14
|
+
"city": {
|
|
15
|
+
"type": "string"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"validations": [],
|
|
19
|
+
"relations": {},
|
|
20
|
+
"acls": [
|
|
21
|
+
{
|
|
22
|
+
"accessType":"EXECUTE",
|
|
23
|
+
"principalType":"ROLE",
|
|
24
|
+
"principalId":"$unauthenticated",
|
|
25
|
+
"permission":"DENY",
|
|
26
|
+
"property":"greet"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"methods": {}
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
module.exports = function enableAuthentication(server) {
|
|
9
|
+
// enable authentication
|
|
10
|
+
server.enableAuth();
|
|
11
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const debug = require('debug')('loopback:example:lb3application');
|
|
9
|
+
|
|
10
|
+
module.exports = async function (app) {
|
|
11
|
+
await app.dataSources.db.automigrate('CoffeeShop');
|
|
12
|
+
|
|
13
|
+
const coffeeShops = await app.models.CoffeeShop.create([
|
|
14
|
+
{
|
|
15
|
+
name: 'Bel Cafe',
|
|
16
|
+
city: 'Vancouver',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'Three Bees Coffee House',
|
|
20
|
+
city: 'San Mateo',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'Caffe Artigiano',
|
|
24
|
+
city: 'Vancouver',
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
27
|
+
debug('Models created: \n', coffeeShops);
|
|
28
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"restApiRoot": "/",
|
|
3
|
+
"remoting": {
|
|
4
|
+
"context": false,
|
|
5
|
+
"rest": {
|
|
6
|
+
"handleErrors": false,
|
|
7
|
+
"handleUnknownPaths": false,
|
|
8
|
+
"normalizeHttpPath": false,
|
|
9
|
+
"xml": false
|
|
10
|
+
},
|
|
11
|
+
"json": {
|
|
12
|
+
"strict": false,
|
|
13
|
+
"limit": "100kb"
|
|
14
|
+
},
|
|
15
|
+
"urlencoded": {
|
|
16
|
+
"extended": true,
|
|
17
|
+
"limit": "100kb"
|
|
18
|
+
},
|
|
19
|
+
"cors": false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta": {
|
|
3
|
+
"sources": [
|
|
4
|
+
"loopback/common/models",
|
|
5
|
+
"loopback/server/models",
|
|
6
|
+
"../common/models",
|
|
7
|
+
"./models"
|
|
8
|
+
],
|
|
9
|
+
"mixins": [
|
|
10
|
+
"loopback/common/mixins",
|
|
11
|
+
"loopback/server/mixins",
|
|
12
|
+
"../common/mixins",
|
|
13
|
+
"./mixins"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"User": {
|
|
17
|
+
"dataSource": "db"
|
|
18
|
+
},
|
|
19
|
+
"AccessToken": {
|
|
20
|
+
"dataSource": "db",
|
|
21
|
+
"public": false
|
|
22
|
+
},
|
|
23
|
+
"ACL": {
|
|
24
|
+
"dataSource": "db",
|
|
25
|
+
"public": false
|
|
26
|
+
},
|
|
27
|
+
"RoleMapping": {
|
|
28
|
+
"dataSource": "db",
|
|
29
|
+
"public": false
|
|
30
|
+
},
|
|
31
|
+
"Role": {
|
|
32
|
+
"dataSource": "db",
|
|
33
|
+
"public": false
|
|
34
|
+
},
|
|
35
|
+
"CoffeeShop": {
|
|
36
|
+
"dataSource": "db",
|
|
37
|
+
"public": true
|
|
38
|
+
}
|
|
39
|
+
}
|