-
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
feat(rest): allow basePath for rest servers #2097
Conversation
|
Can this limitation affect usability of the feature when configuring basePath from an application? Please add an acceptance test showing how a RestApplication can configure basePath. Try to mimic the coding conventions we are using in our example applications (e.g. examples/todo/src/application.ts) - a custom class extending RestApplication where the configuration options are modified inside application's constructor. |
Also: have you considered to refactor RestServer so that setup of express routes is deferred until we need to access the request-handler function? |
6e663c1
to
350f796
Compare
I don't think so. IMO, Anyway, I refactored PTAL. |
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.
Documentation in /docs/site was updated
Would you mind adding a short documentation for basePath
?
Affected artifact templates in packages/cli were updated
Should we extend Application template to explicitly call this.basePath
so that users know where to start when changing the base path?
Affected example projects in examples/* were updated
Is there anything to update here?
55656a8
to
7e5b5ab
Compare
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.
Looks mostly good, please address my two comments below.
No further review is required from my side.
restApp.static('/', ASSETS); | ||
await restApp.start(); | ||
client = createRestAppClient(restApp); | ||
await client.get('/html/index.html').expect(200); |
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 find this test very confusing. As far as I understand givenApplication()
helper, it creates an app with no API routes configured. As I understand app.basePath
, it's intended primarily for customizing the base path of REST APIs.
I see that there are other tests verifying the impact of basePath on different kinds of routes, I agree there is no need to duplicate those tests in rest.application.integration.ts
.
Can you please add a comment here? Explain that in this test, we are invoking a route for static assets, because basePath applies to all kinds of routes, including static assets.
Alternatively, rework this test to use a handler-function route (see the example below) - I think it will make the intent of this test much easier to understand even without comments.
app.route('get', '/status', {/*spec*/}, () => {running: true});
// ...
client.get('/api/status').expect(200, {running: true});
app.component(RestComponent); | ||
const server = await app.getServer(RestServer); | ||
expect(() => { | ||
if (server.requestHandler) { |
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.
If this condition happens to be false, then server.basePath
is not invoked at all and the test fails with a confusing error.
Please convert this if
into an explicit assertion. For example:
expect.assert(!!server.requestHandler, 'requestHandler should have been set up by now');
expect(() => server.basePath('/api')).to.throw(/*...*/);
7e5b5ab
to
1b99be4
Compare
hi @raymondfeng Thanks to every loopback developer. when we will use this "Add basePath configuration" feature ? |
See #918
Some deviation from #918:
basePath
is only available as part ofRestServerConfig
because we set up express routes within the constructor.basePath
only applies to registered routes (including static assets)servers
in openapi spec are adjusted accordinglyChecklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated