@loopback/example-hello-world 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 +1391 -0
- package/LICENSE +25 -0
- package/README.md +74 -0
- package/dist/__tests__/acceptance/application.acceptance.d.ts +1 -0
- package/dist/__tests__/acceptance/application.acceptance.js +31 -0
- package/dist/__tests__/acceptance/application.acceptance.js.map +1 -0
- package/dist/application.d.ts +7 -0
- package/dist/application.js +30 -0
- package/dist/application.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
- package/src/__tests__/acceptance/application.acceptance.ts +38 -0
- package/src/application.ts +33 -0
- package/src/index.ts +30 -0
- package/tsconfig.json +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Copyright (c) IBM Corp. 2018,2019.
|
|
2
|
+
Node module: @loopback/example-hello-world
|
|
3
|
+
This project is licensed under the MIT License, full text below.
|
|
4
|
+
|
|
5
|
+
--------
|
|
6
|
+
|
|
7
|
+
MIT license
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @loopback/example-hello-world
|
|
2
|
+
|
|
3
|
+
A simple hello-world application using LoopBack 4!
|
|
4
|
+
|
|
5
|
+
## Summary
|
|
6
|
+
|
|
7
|
+
This project shows how to write the simplest LoopBack 4 application possible.
|
|
8
|
+
Check out
|
|
9
|
+
[src/application.ts](https://github.com/loopbackio/loopback-next/blob/master/examples/hello-world/src/application.ts)
|
|
10
|
+
to learn how we configured our application to always respond with "Hello
|
|
11
|
+
World!".
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
Before we can begin, you'll need to make sure you have some things installed:
|
|
16
|
+
|
|
17
|
+
- [Node.js](https://nodejs.org/en/) at v10 or greater
|
|
18
|
+
|
|
19
|
+
Additionally, this tutorial assumes that you are comfortable with certain
|
|
20
|
+
technologies, languages and concepts.
|
|
21
|
+
|
|
22
|
+
- JavaScript (ES6)
|
|
23
|
+
- [npm](https://www.npmjs.com/)
|
|
24
|
+
- [REST](https://en.wikipedia.org/wiki/Representational_state_transfer)
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
1. Install the new loopback CLI toolkit.
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm i -g @loopback/cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. Download the "hello-world" application.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
lb4 example hello-world
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3. Switch to the directory.
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
cd loopback4-example-hello-world
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Use
|
|
47
|
+
|
|
48
|
+
Start the app:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
npm start
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The application will start on port `3000`. Use your favourite browser or REST
|
|
55
|
+
client to access any path with a GET request, and watch it return
|
|
56
|
+
`Hello world!`.
|
|
57
|
+
|
|
58
|
+
## Contributions
|
|
59
|
+
|
|
60
|
+
- [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)
|
|
61
|
+
- [Join the team](https://github.com/loopbackio/loopback-next/issues/110)
|
|
62
|
+
|
|
63
|
+
## Tests
|
|
64
|
+
|
|
65
|
+
Run `npm test` from the root folder.
|
|
66
|
+
|
|
67
|
+
## Contributors
|
|
68
|
+
|
|
69
|
+
See
|
|
70
|
+
[all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/example-hello-world
|
|
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 testlab_1 = require("@loopback/testlab");
|
|
8
|
+
const application_1 = require("../../application");
|
|
9
|
+
describe('Application', () => {
|
|
10
|
+
let app;
|
|
11
|
+
let client;
|
|
12
|
+
before(givenAnApplication);
|
|
13
|
+
before(async () => {
|
|
14
|
+
await app.start();
|
|
15
|
+
client = testlab_1.createRestAppClient(app);
|
|
16
|
+
});
|
|
17
|
+
after(async () => {
|
|
18
|
+
await app.stop();
|
|
19
|
+
});
|
|
20
|
+
it('responds with hello world', async () => {
|
|
21
|
+
const response = await client.get('/').expect(200);
|
|
22
|
+
testlab_1.expect(response.text).to.eql('Hello World!');
|
|
23
|
+
});
|
|
24
|
+
function givenAnApplication() {
|
|
25
|
+
app = new application_1.HelloWorldApplication({
|
|
26
|
+
rest: testlab_1.givenHttpServerConfig(),
|
|
27
|
+
disableConsoleLog: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=application.acceptance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application.acceptance.js","sourceRoot":"","sources":["../../../src/__tests__/acceptance/application.acceptance.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,6CAA6C;AAC7C,+CAA+C;AAC/C,gEAAgE;;AAEhE,+CAK2B;AAC3B,mDAAwD;AAExD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAI,GAA0B,CAAC;IAC/B,IAAI,MAAc,CAAC;IAEnB,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAC3B,MAAM,CAAC,KAAK,IAAI,EAAE;QAChB,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,GAAG,6BAAmB,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,KAAK,IAAI,EAAE;QACf,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QACzC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnD,gBAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,SAAS,kBAAkB;QACzB,GAAG,GAAG,IAAI,mCAAqB,CAAC;YAC9B,IAAI,EAAE,+BAAqB,EAAE;YAC7B,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ApplicationConfig } from '@loopback/core';
|
|
2
|
+
import { RestApplication } from '@loopback/rest';
|
|
3
|
+
export { ApplicationConfig };
|
|
4
|
+
export declare class HelloWorldApplication extends RestApplication {
|
|
5
|
+
constructor(options?: ApplicationConfig);
|
|
6
|
+
start(): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/example-hello-world
|
|
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.HelloWorldApplication = void 0;
|
|
8
|
+
const rest_1 = require("@loopback/rest");
|
|
9
|
+
class HelloWorldApplication extends rest_1.RestApplication {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
super(options);
|
|
12
|
+
// In this example project, we configure a sequence that always
|
|
13
|
+
// returns the same HTTP response: Hello World!
|
|
14
|
+
// Learn more about the concept of Sequence in our docs:
|
|
15
|
+
// http://loopback.io/doc/en/lb4/Sequence.html
|
|
16
|
+
this.handler(({ response }, sequence) => {
|
|
17
|
+
sequence.send(response, 'Hello World!');
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async start() {
|
|
21
|
+
var _a;
|
|
22
|
+
await super.start();
|
|
23
|
+
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.disableConsoleLog)) {
|
|
24
|
+
const rest = await this.getServer(rest_1.RestServer);
|
|
25
|
+
console.log(`REST server running on port: ${await rest.get('rest.port')}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.HelloWorldApplication = HelloWorldApplication;
|
|
30
|
+
//# sourceMappingURL=application.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,6CAA6C;AAC7C,+CAA+C;AAC/C,gEAAgE;;;AAGhE,yCAA2D;AAG3D,MAAa,qBAAsB,SAAQ,sBAAe;IACxD,YAAY,UAA6B,EAAE;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,+DAA+D;QAC/D,+CAA+C;QAC/C,wDAAwD;QACxD,gDAAgD;QAChD,IAAI,CAAC,OAAO,CAAC,CAAC,EAAC,QAAQ,EAAC,EAAE,QAAQ,EAAE,EAAE;YACpC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,CAAC,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,iBAAiB,CAAA,EAAE;YACpC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,iBAAU,CAAC,CAAC;YAC9C,OAAO,CAAC,GAAG,CACT,gCAAgC,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAC9D,CAAC;SACH;IACH,CAAC;CACF;AAvBD,sDAuBC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/example-hello-world
|
|
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 application_1 = require("./application");
|
|
10
|
+
async function main(config) {
|
|
11
|
+
const app = new application_1.HelloWorldApplication();
|
|
12
|
+
await app.start();
|
|
13
|
+
return app;
|
|
14
|
+
}
|
|
15
|
+
exports.main = main;
|
|
16
|
+
if (require.main === module) {
|
|
17
|
+
// Run the application
|
|
18
|
+
const config = {
|
|
19
|
+
rest: {
|
|
20
|
+
port: +((_a = process.env.PORT) !== null && _a !== void 0 ? _a : 3000),
|
|
21
|
+
host: (_b = process.env.HOST) !== null && _b !== void 0 ? _b : 'localhost',
|
|
22
|
+
openApiSpec: {
|
|
23
|
+
// useful when used with OpenAPI-to-GraphQL to locate your application
|
|
24
|
+
setServersFromRequest: true,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
main(config).catch(err => {
|
|
29
|
+
console.error('Cannot start the application.', err);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,6CAA6C;AAC7C,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+CAAuE;AAEhE,KAAK,UAAU,IAAI,CAAC,MAAyB;IAClD,MAAM,GAAG,GAAG,IAAI,mCAAqB,EAAE,CAAC;IACxC,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IAClB,OAAO,GAAG,CAAC;AACb,CAAC;AAJD,oBAIC;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;SACF;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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loopback/example-hello-world",
|
|
3
|
+
"description": "A simple hello-world Application using LoopBack 4",
|
|
4
|
+
"version": "3.0.1",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"loopback",
|
|
7
|
+
"LoopBack",
|
|
8
|
+
"example",
|
|
9
|
+
"tutorial"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"author": "IBM Corp.",
|
|
15
|
+
"copyright.owner": "IBM Corp.",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/loopbackio/loopback-next.git",
|
|
19
|
+
"directory": "examples/hello-world"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": "^10.16 || 12 || 14 || 16"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"acceptance": "lb-mocha \"dist/__tests__/acceptance/**/*.js\"",
|
|
26
|
+
"build": "lb-tsc",
|
|
27
|
+
"build:watch": "lb-tsc --watch",
|
|
28
|
+
"clean": "lb-clean *example-hello-world*.tgz dist *.tsbuildinfo package",
|
|
29
|
+
"verify": "npm pack && tar xf *example-hello-world*.tgz && tree package && npm run clean",
|
|
30
|
+
"lint": "npm run prettier:check && npm run eslint",
|
|
31
|
+
"lint:fix": "npm run eslint:fix && npm run prettier:fix",
|
|
32
|
+
"prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"",
|
|
33
|
+
"prettier:check": "npm run prettier:cli -- -l",
|
|
34
|
+
"prettier:fix": "npm run prettier:cli -- --write",
|
|
35
|
+
"eslint": "lb-eslint --report-unused-disable-directives .",
|
|
36
|
+
"eslint:fix": "npm run eslint -- --fix",
|
|
37
|
+
"pretest": "npm run rebuild",
|
|
38
|
+
"test": "lb-mocha --allow-console-logs \"dist/__tests__/**/*.js\"",
|
|
39
|
+
"posttest": "npm run lint",
|
|
40
|
+
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
|
|
41
|
+
"rebuild": "npm run clean && npm run build",
|
|
42
|
+
"prestart": "npm run rebuild",
|
|
43
|
+
"start": "node ."
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@loopback/core": "^2.17.0",
|
|
50
|
+
"@loopback/rest": "^10.0.1",
|
|
51
|
+
"tslib": "^2.3.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@loopback/build": "^7.0.1",
|
|
55
|
+
"@loopback/eslint-config": "^11.0.1",
|
|
56
|
+
"@loopback/testlab": "^3.4.3",
|
|
57
|
+
"@types/node": "^10.17.60",
|
|
58
|
+
"eslint": "^7.32.0",
|
|
59
|
+
"typescript": "~4.3.5"
|
|
60
|
+
},
|
|
61
|
+
"gitHead": "1df36bb1ee2e513d9e197bd6010c4cfb296d50b8"
|
|
62
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2019. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/example-hello-world
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Client,
|
|
8
|
+
createRestAppClient,
|
|
9
|
+
expect,
|
|
10
|
+
givenHttpServerConfig,
|
|
11
|
+
} from '@loopback/testlab';
|
|
12
|
+
import {HelloWorldApplication} from '../../application';
|
|
13
|
+
|
|
14
|
+
describe('Application', () => {
|
|
15
|
+
let app: HelloWorldApplication;
|
|
16
|
+
let client: Client;
|
|
17
|
+
|
|
18
|
+
before(givenAnApplication);
|
|
19
|
+
before(async () => {
|
|
20
|
+
await app.start();
|
|
21
|
+
client = createRestAppClient(app);
|
|
22
|
+
});
|
|
23
|
+
after(async () => {
|
|
24
|
+
await app.stop();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('responds with hello world', async () => {
|
|
28
|
+
const response = await client.get('/').expect(200);
|
|
29
|
+
expect(response.text).to.eql('Hello World!');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function givenAnApplication() {
|
|
33
|
+
app = new HelloWorldApplication({
|
|
34
|
+
rest: givenHttpServerConfig(),
|
|
35
|
+
disableConsoleLog: true,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/example-hello-world
|
|
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 {RestApplication, RestServer} from '@loopback/rest';
|
|
8
|
+
export {ApplicationConfig};
|
|
9
|
+
|
|
10
|
+
export class HelloWorldApplication extends RestApplication {
|
|
11
|
+
constructor(options: ApplicationConfig = {}) {
|
|
12
|
+
super(options);
|
|
13
|
+
|
|
14
|
+
// In this example project, we configure a sequence that always
|
|
15
|
+
// returns the same HTTP response: Hello World!
|
|
16
|
+
// Learn more about the concept of Sequence in our docs:
|
|
17
|
+
// http://loopback.io/doc/en/lb4/Sequence.html
|
|
18
|
+
this.handler(({response}, sequence) => {
|
|
19
|
+
sequence.send(response, 'Hello World!');
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async start() {
|
|
24
|
+
await super.start();
|
|
25
|
+
|
|
26
|
+
if (!this.options?.disableConsoleLog) {
|
|
27
|
+
const rest = await this.getServer(RestServer);
|
|
28
|
+
console.log(
|
|
29
|
+
`REST server running on port: ${await rest.get('rest.port')}`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/example-hello-world
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {ApplicationConfig, HelloWorldApplication} from './application';
|
|
7
|
+
|
|
8
|
+
export async function main(config: ApplicationConfig) {
|
|
9
|
+
const app = new HelloWorldApplication();
|
|
10
|
+
await app.start();
|
|
11
|
+
return app;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (require.main === module) {
|
|
15
|
+
// Run the application
|
|
16
|
+
const config = {
|
|
17
|
+
rest: {
|
|
18
|
+
port: +(process.env.PORT ?? 3000),
|
|
19
|
+
host: process.env.HOST ?? 'localhost',
|
|
20
|
+
openApiSpec: {
|
|
21
|
+
// useful when used with OpenAPI-to-GraphQL to locate your application
|
|
22
|
+
setServersFromRequest: true,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
main(config).catch(err => {
|
|
27
|
+
console.error('Cannot start the application.', err);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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/core/tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../../packages/rest/tsconfig.json"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "../../packages/testlab/tsconfig.json"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|