-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(server): fallthrough non GET
and HEAD
request to routes defined in after option
#2374
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2374 +/- ##
==========================================
- Coverage 93.95% 93.75% -0.21%
==========================================
Files 34 34
Lines 1291 1297 +6
Branches 368 370 +2
==========================================
+ Hits 1213 1216 +3
- Misses 77 79 +2
- Partials 1 2 +1
Continue to review full report at Codecov.
|
lib/Server.js
Outdated
@@ -390,13 +390,25 @@ class Server { | |||
|
|||
if (Array.isArray(contentBase)) { | |||
contentBase.forEach((item) => { | |||
this.app.use(contentBasePublicPath, serveIndex(item)); | |||
this.app.use(contentBasePublicPath, (req, res, next) => { | |||
if (req.method !== 'GET') { |
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.
Not sure it is good solution, developers can want to handle GET
in own middleware too
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.
AFAIK, serve-index
let GET
request that it can't handle fall-back to the next middleware, it's just non-GET request that are blindly replied as 405
.
This is basically a revert of the change from app.get
to app.use
done in #2150 while still keeping the contentBasePublicPath
feature.
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 (req.method !== 'GET') { | |
if (req.method !== 'GET' && req.method !== 'HEAD') { |
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.
But based on previous implementation, we handle only GET
, so i think we can merge this, we need fix it for server-static
too https://github.com/webpack/webpack-dev-server/pull/2150/files#diff-15fb51940da53816af13330d8ce69b4eR341
/cc @iamandrewluca
@evilebottnawi the |
I'm taking a look into |
0bf6e29
to
02320d3
Compare
@jvasseur also make sure you check also for if (req.method !== 'GET' && req.method !== 'HEAD') {
// ... Also I think return serveIndex(item)(req, res, next); |
@iamandrewluca I've added the check for |
recommend to rename PR into
|
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.
@jvasseur pls add a comment in code before |
GET
and HEAD
request to routes defined in after option
Fix a bug introduced in cee700d where the serveIndex feature where always replying instead of forwarding requests to the next middleware.
5b86099
02320d3
to
5b86099
Compare
@iamandrewluca done |
@jvasseur add at the end of PR description this. It will automatically close the issue when PR is merged.
|
Done |
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.
lgtm
Thanks! |
For Bugs and Features; did you add new tests?
Yes
Motivation / Use-Case
Before #2150, non-GET request where forwarded to any middleware defined in the after option, since #2150, they are handled by
serve-index
instead that always reply with a 405 error.This fix issue #2370.
Breaking Changes
No
Additional Info
Closes #2370