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
James2y 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
albertmgtaOP2y 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
James2y ago
The file will be generated after building with next-on-pages
albertmgta
albertmgtaOP2y ago
I can't see this file
James
James2y 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
albertmgtaOP2y ago
ok, wait
albertmgta
albertmgtaOP2y ago
building... wait a sec
James
James2y 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
albertmgtaOP2y ago
Thank you very much! You are very kind
albertmgta
albertmgtaOP2y ago
attach file ".vercel/output/config.json"
James
James2y 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
albertmgtaOP2y ago
All works well , thx man !!!! 👏👏
James
James2y ago
That's great! Hopefully it'll be merged soon 🙂 Just to let you know, this fix is included in the latest release 🙂
NastykSwED
NastykSwED2y 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
NastykSwED2y 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
James2y 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
NastykSwED2y 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
NastykSwED2y ago
NastykSwED
NastykSwED2y 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
NastykSwED2y ago
main branch*
NastykSwED
NastykSwED2y ago
dev branch*
NastykSwED
NastykSwED2y ago
main network*
NastykSwED
NastykSwED2y ago
dev network*
NastykSwED
NastykSwED2y 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
James2y 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
NastykSwED2y 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
NastykSwED2y ago
Want results from more Discord servers?
Add your server