Infinite redirection in Cloudflare Pages

Hello! We have deployed some next.js projects we had in Vercel in Cloudflare. Everything works fine, except when someone accesses a URL by putting a slash / at the end of it. It goes into an infinite loop. Can someone help us? URL that works fine: https://demo.tkting.io/es/club/club-test URL with infinite loop: https://demo.tkting.io/es/club/club-test/ In the next.config.js configuration the "trainlingSlash" is set to false. If we enable it, when entering any route it stays in infinite loop. Thank you very much for your valuable help
28 Replies
James
James13mo ago
Hello, would you be able to provide me with the generated config file at .vercel/output/config.json? Could you also please confirm which version of @cloudflare/next-on-pages you are using?
albertmgta
albertmgta13mo ago
Hi! Point 1: Where can I find the file .vercel/output/config.json ? Point 2: "@cloudflare/next-on-pages": "^1.0.1", Thx!
James
James13mo ago
The file will be generated after building with next-on-pages
albertmgta
albertmgta13mo ago
I can't see this file
James
James13mo ago
It's not one of the files that gets deployed, you'll need to run npx @cloudflare/next-on-pages locally to get it - I probably should have clarified that at first, apologies for the confusion.
albertmgta
albertmgta13mo ago
ok, wait
albertmgta
albertmgta13mo ago
building... wait a sec
James
James13mo ago
No worries, I have some packing to do so I'll most likely take a look later tonight or at some point tomorrow, and try and identify the cause and a fix using the config you provide.
albertmgta
albertmgta13mo ago
Thank you very much! You are very kind
albertmgta
albertmgta13mo ago
attach file ".vercel/output/config.json"
James
James13mo ago
Hey there @albertmgta, I believe I might have found the cause. Could you please try using the prerelease in this PR and let me know if the problem is still occuring? https://github.com/cloudflare/next-on-pages/pull/291#issuecomment-1574301372
albertmgta
albertmgta13mo ago
All works well , thx man !!!! 👏👏
James
James12mo ago
That's great! Hopefully it'll be merged soon 🙂 Just to let you know, this fix is included in the latest release 🙂
NastykSwED
NastykSwED12mo ago
Hi @5927 thanks for the solution to the problem we had. I am @albertmgta mate. Now we are experiencing another problem. I leave some screenshots for you to see
NastykSwED
NastykSwED12mo ago
After running the command "npx @cloudflare/next-on-pages" and then running "npx wrangler pages dev .vercel/output/static --compatibility-flag=nodejs_compat" we found this problem. And the same thing happens when we build to production. Our project just doesn't run
James
James12mo ago
The invalid URL string makes me think you might be using relative URLs in edge runtime pages, or something like that I'm not really sure, hard to tell without seeing the code it's referencing tbh
NastykSwED
NastykSwED12mo ago
that doesn't make much sense as we are running our project with the latest version of @next-on-pages and it works normally. However these days we have tried to upload some commits and they all fail with this error:
NastykSwED
NastykSwED12mo ago
NastykSwED
NastykSwED12mo ago
this is on the main branc, if we deploy on dev branc with a preview mode this is on the main branch, if we deploy to the development branch with a preview mode this error does not happen. Also we see that in the dev branch that file is not downloaded while in the main branch it is. In cloudflare we can see that the file exists.
NastykSwED
NastykSwED12mo ago
main branch*
NastykSwED
NastykSwED12mo ago
dev branch*
NastykSwED
NastykSwED12mo ago
main network*
NastykSwED
NastykSwED12mo ago
dev network*
NastykSwED
NastykSwED12mo ago
And all our routes use the runtime edge. What we find more strange is the fact that it works with a previous commit and if we move to that commit and add a blank line for example and send the commit to main we have the same problem.
James
James12mo ago
That's a different error to the other screenshot, but yeah, that is not good. That _next/static having issues related to next-on-pages because we exclude that directory from invoking the worker, so that makes me rather confused as to where it would be all of a sudden coming from. Yeah it really doesn't make much sense why that would only occur on main too. Is there some kind of caching enabled on your domain that is interfering perhaps
NastykSwED
NastykSwED12mo ago
In our project we have 3 domains, one of them is from cloudflare where we are experiencing these problems. We have also noticed that if you enter the domain "www.our-domain.com" the problem disappears. However if you enter without the "www" the error occurs, is this due to a misconfiguration of the dns of this domain? Because in the commit where the web is currently running normally this did not happen. I tried purging the domain cache but we are still experiencing the problem.
NastykSwED
NastykSwED12mo ago