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]: 301 Moved Permanently from middleware ended up with 307 Temporary Redirect #808

Closed
1 task done
strofimo opened this issue Jun 21, 2024 · 1 comment · Fixed by #810
Closed
1 task done
Labels
bug Something isn't working

Comments

@strofimo
Copy link
Contributor

strofimo commented Jun 21, 2024

next-on-pages environment related information

System:
Platform: linux
Arch: x64
Version: #1 SMP Fri Mar 29 23:14:13 UTC 2024
CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
Memory: 15 GB
Shell: /bin/bash
Package Manager Used: npm (9.6.3)

Relevant Packages:
@cloudflare/next-on-pages: 1.11.3
vercel: 34.2.4
next: 14.1.0

Description

Cloudflare next-on-pages do 307 redirect while it has to be 301.

Reproduction

I have created a minimal reproducible example in this repo

How to set it up

git clone https://github.com/strofimo/cf-middleware-move-permanently.git
cd cf-middleware-move-permanently
npm i

Run NextJS Dev to see what are the expected redirect result

npm run dev
# accessing http://localhost:3000 lead to 301 Moved Permanently
# ▲ Next.js 14.1.0
# - Local:        http://localhost:3000

This is the expected behave for a next js app.

Run Cloudflare pages preview using wrangler

npm run preview
# accessing http://localhost:8788 lead to 307 Temporary Redirect
# [wrangler:inf] Ready on http://localhost:8788

Pages Deployment Method

None

Pages Deployment ID

No response

Additional Information

No response

Would you like to help?

  • Would you like to help fixing this bug?
@strofimo strofimo added the bug Something isn't working label Jun 21, 2024
@strofimo
Copy link
Contributor Author

strofimo commented Jun 21, 2024

It looks like the issue is here where we in redirect case did not set status. But because this.headers.middlewareLocation is set we bug out here before we set status in applyRouteStatus. So when we essentially returns here the this.status is undefined and we return 307.

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