nuxt / nuxt

The Intuitive Vue Framework.

Home Page:https://nuxt.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong status codes in server plugins

imslepov opened this issue · comments

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

See reproduction link

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

Would you see if you can reproduce this in pure Nitro (reproduction sandbox), and if so, raise there? 🙏

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.