Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions packages/authentication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,36 +145,33 @@ export class MySequence implements SequenceHandler {
Finally, put it all together in your application class:

```ts
import {Application} from '@loopback/core';
import {
AuthenticationComponent,
AuthenticationBindings,
} from '@loopback/authentication';
import {RestComponent, RestServer} from '@loopback/rest';
import {RestApplication, RestServer} from '@loopback/rest';
import {MyAuthStrategyProvider} from './providers/auth-strategy';
import {MyController} from './controllers/my-controller';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at lines 148 and 153, Application and RestComponent aren't needed anymore

import {MySequence} from './sequence';

class MyApp extends Application {
class MyApp extends RestApplication {
constructor() {
super({
components: [AuthenticationComponent, RestComponent],
rest: {
sequence: MySequence
},
controllers: [MyController],
});
super();

this.component(AuthenticationComponent);
this
.bind(AuthenticationBindings.STRATEGY)
.toProvider(MyAuthStrategyProvider);

this.sequence(MySequence);

this.controller(MyController);
}

async start() {
const server = await this.getServer(RestServer);

server.bind(AuthenticationBindings.STRATEGY)
.toProvider(MyAuthStrategyProvider);
await super.start();

const server = await this.getServer(RestServer);
console.log(`REST server running on port: ${server.getSync('rest.port')}`);
}
}
Expand Down
20 changes: 6 additions & 14 deletions packages/cli/generators/app/templates/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,25 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Application, ApplicationConfig} from '@loopback/core';
import {RestComponent, RestServer} from '@loopback/rest';
import {ApplicationConfig} from '@loopback/core';
import {RestApplication, RestServer} from '@loopback/rest';
import {PingController} from './controllers/ping.controller';
import {MySequence} from './sequence';

export class <%= project.applicationName %> extends Application {
export class <%= project.applicationName %> extends RestApplication {
constructor(options?: ApplicationConfig) {
// Allow options to replace the defined components array, if desired.
options = Object.assign(
{},
{
components: [RestComponent],
},
options,
);
super(options);
this.server(RestServer);
this.sequence(MySequence);
this.setupControllers();
}

async start() {
await super.start();

const server = await this.getServer(RestServer);
server.sequence(MySequence);
const port = await server.get('rest.port');
console.log(`Server is running at http://127.0.0.1:${port}`);
console.log(`Try http://127.0.0.1:${port}/ping`);
return await super.start();
}

setupControllers() {
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ describe('app-generator specfic files', () => {
assert.file('src/application.ts');
assert.fileContent(
'src/application.ts',
/class MyAppApplication extends Application/
/class MyAppApplication extends RestApplication/
);
assert.fileContent('src/application.ts', /constructor\(/);
assert.fileContent('src/application.ts', /async start\(/);
assert.fileContent('src/application.ts', /RestComponent/);

assert.file('src/index.ts');
assert.fileContent('src/index.ts', /new MyAppApplication/);
Expand All @@ -48,7 +47,10 @@ describe('app-generator specfic files', () => {
/@get\('\/ping'\)/
);
assert.fileContent('src/controllers/ping.controller.ts', /ping\(\)/);
assert.fileContent('src/controllers/ping.controller.ts', /\'\@loopback\/openapi\-v2\'/);
assert.fileContent(
'src/controllers/ping.controller.ts',
/\'\@loopback\/openapi\-v2\'/
);

assert.file;
});
Expand Down
3 changes: 0 additions & 3 deletions packages/example-hello-world/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

// tslint:disable-next-line:no-unused-variable
import {Application} from '@loopback/core';

import {RestApplication, RestServer} from '@loopback/rest';

export class HelloWorldApplication extends RestApplication {
Expand Down
4 changes: 2 additions & 2 deletions packages/example-log-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import {
} from 'loopback4-example-log-extension';
// Other imports ...

class LogApp extends LogLevelMixin(Application) {
class LogApp extends LogLevelMixin(RestApplication) {
constructor() {
super({
components: [RestComponent, LogComponent],
components: [LogComponent],
logLevel: LOG_LEVEL.ERROR,
controllers: [MyController]
});
Expand Down
16 changes: 6 additions & 10 deletions packages/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,17 @@ Here's a basic "Hello World" application using `@loopback/core` and
`@loopback/rest`:

```ts
import {Application} from '@loopback/core';
import {RestComponent, RestServer} from '@loopback/rest';
import {RestApplication, RestServer} from '@loopback/rest';

const app = new Application({
components: [
RestComponent,
]
const app = new RestApplication();
app.handler((sequence, request, response) => {
sequence.send(response, 'hello world');
});

(async function start() {
const rest = await app.getServer(RestServer);
rest.handler((sequence, request, response) => {
sequence.send(response, 'hello world');
});
await app.start();

const rest = await app.getServer(RestServer);
console.log(`REST server running on port: ${rest.getSync('rest.port')}`);
})();
```
Expand Down
1 change: 1 addition & 0 deletions packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@loopback/openapi-spec": "^4.0.0-alpha.25",
"@loopback/openapi-v2": "^4.0.0-alpha.10",
"@types/http-errors": "^1.6.1",
"@types/node": "^8.5.9",
"body": "^5.1.0",
"debug": "^3.1.0",
"http-errors": "^1.6.1",
Expand Down