-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
Everything returns 404 with Koa #174
Comments
Here is an ugly but functional wrapper to workaround the issue if you are using Koa. Be careful, you must set Depending on your setup you could still come across some strange behavior, specially if using on of those complex webpack hot middleware setups. An example of strange behavior may be that some of your assets being served(response body set) but with a 404 response code. koa.use(async function (ctx, next) {
let prevStatus = ctx.res.statusCode;
ctx.res.statusCode = 200;
await c2k(devMiddleware)(ctx, function() {
ctx.res.statusCode = prevStatus;
return next();
});
}); |
@javiertury Yes, it is a temporary workaround. And we also need a final solution. |
Fixes in #175 |
Reproduce
Then all response statuses are 404.
Reason
We should not set statusCode explicitly, see here
Actually, koa automatically set the statusCode to
404
by default (see koa2, and koa), but the default setting of statusCode does not change thethis._explicitStatus
, soctx.body = something
will set the statusCode to200
(here).But doing
res.statusCode = res.statusCode || 200
makes all responses 404, because it will changethis._explicitStatus
totrue
.Conclusion
Related Issue
The text was updated successfully, but these errors were encountered: