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
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?Hi!
Point 1:
Where can I find the file .vercel/output/config.json ?
Point 2:
"@cloudflare/next-on-pages": "^1.0.1",
Thx!
The file will be generated after building with next-on-pages
I can't see this file
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.ok, wait
building... wait a sec
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.
Thank you very much! You are very kind
attach file ".vercel/output/config.json"
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
All works well , thx man !!!! 👏👏
That's great! Hopefully it'll be merged soon 🙂
Just to let you know, this fix is included in the latest release 🙂
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
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
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
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:
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.
main branch*
dev branch*
main network*
dev network*
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.
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 perhapsIn 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.