Wrong status codes in server plugins
imslepov opened this issue · comments
Daniel Slepov commented
Environment
- Operating System:
Darwin
- Node Version:
v20.12.2
- Nuxt Version:
3.11.2
- CLI Version:
3.11.1
- Nitro Version:
2.9.6
- Package Manager:
npm@10.5.0
- Builder:
-
- User Config:
devtools
- Runtime Modules:
-
- Build Modules:
-
Reproduction
Describe the bug
If using the render:response
and afterResponse
hooks in the server plugin, the statusCode
doesn't match the one actually sent.
// File: server/plugins/OnResponsePlugin.ts
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('render:response', (response) => {
console.log('[render:response] statusCode:', response.statusCode); // always 200
});
nitroApp.hooks.hook('afterResponse', (event) => {
console.log('[afterResponse] statusCode: ' + event.node.res.statusCode); // always 200
});
});
Additional context
No response
Logs
No response
StackBlitz commented
Start a new pull request in StackBlitz Codeflow.
Daniel Roe commented
Would you see if you can reproduce this in pure Nitro (reproduction sandbox), and if so, raise there? 🙏
Daniel Slepov commented
Hmm... Nitro doesn't hook the render:response
(which is okay) and afterResponse
, but in the beforeResponse
hook this bug repeats, also returning a status code of 200. See Nitro's reproduction.