-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(example-getting-started): use RestApplication #955
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have this in the boot
PR but it's a great idea to land this as a separate change. Left a few comments.
import {Application, ApplicationConfig} from '@loopback/core'; | ||
import {RestComponent} from '@loopback/rest'; | ||
import {ApplicationConfig} from '@loopback/core'; | ||
import {RestComponent, RestApplication} from '@loopback/rest'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You no longer need RestComponent
.
@@ -30,6 +30,7 @@ | |||
"dependencies": { | |||
"@loopback/context": "^4.0.0-alpha.29", | |||
"@loopback/core": "^4.0.0-alpha.31", | |||
"@loopback/openapi-spec": "^4.0.0-alpha.23", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this being added? (Don't see it being used in the package).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be used in todo.model.ts
, but the compiler didn't complain about the package not being a dependency though, it's weird. It's entirely unrelated to migrating to RestApplication
btw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's because this example still uses top-down approach to define the schema
for a model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird indeed that it wasn't complaining about the dependency being missing before. Makes me wonder if something is broken / needs to be investigated with out build process. (Not a blocker for this PR ~ Great catch!)
07c643e
to
c80152d
Compare
The changes look good to me. There is more cleanup related to See e.g. const app = new RestApplication();
// ...
(async function start() {
const server = await app.getServer(RestServer);
const route = new Route('get', '/', spec, greet);
server.route(route);
await app.start();
})(); Proposed update: const app = new RestApplication();
const route = new Route('get', '/', spec, greet);
app.route(route);
// ...
(async function start() {
await app.start();
})(); We need to check all places that contain REST-related configuration in |
@bajtos I'll work on a PR for your proposal at |
c80152d
to
b8a6381
Compare
@bajtos On second thought, I've noticed that almost all examples that set up rest config have it done in the For example, our own CLI template sets up the config inside the async 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();
} This issue may need more discussion and I'd feel it might be better dealt in a separate issue. |
async 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();
}
IIRC, the original code snippets were configuring sequence & routes in the constructor. This setup code was moved to async start function after @kjdelisle implemented support for multiple REST servers. I was never happy about that change to be honest. For example, it means that code inspecting application's OpenAPI spec (think of I am ok to leave those changes out of scope of this PR, but I think they are part of #846. Let me leave a comment there too. |
See #968 |
application.ts
now extendsRestApplication
instead ofApplication
@loopback/openapi-spec
fortodo.model.ts
)Checklist
npm test
passes on your machinepackages/cli
were updatedpackages/example-*
were updated