-
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(rest): remove trailing slash for routing match #2355
Conversation
Please note the explorer redirect test is failing as we now treat What do you think? Should we fix the explorer redirect for |
I added commit 402a80d to make sure all tests are passing. |
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.
Please revert the changes in REST API Explorer.
The rest of the patch looks good to me.
@@ -36,11 +36,12 @@ describe('API Explorer (acceptance)', () => { | |||
.expect(/<title>LoopBack API Explorer/); | |||
}); | |||
|
|||
it('redirects from "/explorer" to "/explorer/"', async () => { | |||
it('exposes API Explorer at "/explorer"', async () => { |
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.
This redirect is important because the way how relative paths are resolved in the browser. When the SPA UI is served from /explorer
, a path like src="swagger-ui.js"
is resolved to /swagger-ui.js
instead of /explorer/swagger-ui.js
.
I don't see how your patch is fixing this problem.
Can you revert the changes in REST Explorer please?
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.
Instead of depending on redirect, I updated index.html.ejs
to honor explorerPath
and it works now for both http://localhost:3000/explorer
and http://localhost:3000/explorer/
.
@bajtos Without 402a80d, CI is failing. See https://travis-ci.org/strongloop/loopback-next/jobs/490404103. After we normalizing the key for route matching, |
d1f4243
to
0eeae5b
Compare
@bajtos I improved |
@bajtos PTAL |
That looks like a breaking change to me! I agree that I am concerned that the behavior you are proposing here will be confusing to our users: they register handlers for two different paths, the framework happily accepts them both and then only one handler is invoked for both paths, the other handler being silently ignored. |
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 am concerned that we don't have any automated test coverage to verify that API Explorer is using correct paths to front-end assets.
Ideally, we can use a tool like https://www.npmjs.com/package/jsdom to parse the index HTML and verify the links. (Using a headless Chrome would be even better, but that feels like an overkill to me.)
At minimum, we should do a regexp-based check to verify that src
attributes are using the right relative path.
<link rel="stylesheet" type="text/css" href="./swagger-ui.css"> | ||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /> | ||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" /> | ||
<link rel="stylesheet" type="text/css" href="<%- explorerPath %>/swagger-ui.css"> |
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.
Are you sure this is going to work when the app is running behind a reverse proxy like nginx?
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 the same deal with or without this change. See #2293.
FYI: Express has the following setting to control the trialing
|
I think we should have an option to configure this behavior. Btw, the the setting is simply |
@bajtos @hacksparrow I extracted the fix for #2188 into a new PR - #2375 and leave the trailing slash handling in this PR, which may require more discussions. |
14a215e
to
086c5fc
Compare
086c5fc
to
8bdfa7c
Compare
Superseded by #2419 |
Handle trailing slash for urls.
Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated