Skip to content
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

Wrong status codes in server plugins #27248

Open
imslepov opened this issue May 16, 2024 · 3 comments
Open

Wrong status codes in server plugins #27248

imslepov opened this issue May 16, 2024 · 3 comments

Comments

@imslepov
Copy link

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

Copy link

stackblitz bot commented May 16, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@danielroe
Copy link
Member

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

@imslepov
Copy link
Author

imslepov commented May 16, 2024

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.

UPD: It looks like a bug in unjs/h3. I have created an issue for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants