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

[🐛 Bug]: status code does not match what is set in rewrite #945

Open
1 task done
yoohahn opened this issue Feb 27, 2025 · 0 comments · May be fixed by #953
Open
1 task done

[🐛 Bug]: status code does not match what is set in rewrite #945

yoohahn opened this issue Feb 27, 2025 · 0 comments · May be fixed by #953
Labels
bug Something isn't working

Comments

@yoohahn
Copy link

yoohahn commented Feb 27, 2025

next-on-pages environment related information

System:
Platform: linux
Arch: x64
Version: #202405300957173877096822.04~d5f7c84 SMP PREEMPT_DYNAMIC Wed F
CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
Memory: 31 GB
Shell: /bin/zsh
Package Manager Used: npm (10.9.2)

Relevant Packages:
@cloudflare/next-on-pages: 1.13.8
vercel: N/A
next: 15.2.0

Description

When sending a custom status code using NextResponse.rewrite Next On Pages does not use that code. Instead it always send 200.

Reproduction

Example code;

if (req.nextUrl.href.includes("statusCode")) {
  const status = Number(req.nextUrl.searchParams.get("statusCode"));
  console.log("Middleware should respond with status code:", status);
  return NextResponse.rewrite(req.url, {
    status,
    headers: {
      ...req.headers,
      "X-Status": String(status),
    },
  });
}

Example repo;
https://github.com/yoohahn/next-test

$ yarn start # to test nextjs deploy localy
$ yarn preview # to test pages deploy localy

When I go to https://localhost:3333/?statusCode=404 I expect the status code to be 404. That is correct when deploying to Vercel or running locally.

If I host in Pages and go to the same URL I expect 404, but I get 200. https://localhost:8788/?statusCode=404.

Pages Deployment Method

None

Pages Deployment ID

No response

Additional Information

I was trying to set next on pages locally but e2e hangs on fixtures and I cant get it to run locally. So sadly I can't fix it my self :(

Would you like to help?

  • Would you like to help fixing this bug?
@yoohahn yoohahn added the bug Something isn't working label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant