Does pages support Next.js rewrites?

Does pages support Next.js rewrites in next.config.js?
11 Replies
James
James•2y ago
Not at the moment. Should be coming in the new routing system.
ysm
ysmOP•2y ago
how about headers and redirects in next.config.js?
James
James•2y ago
It's the same with both of those.
ysm
ysmOP•2y ago
Thanks! Is there any thread or github issue or something I can follow for this update?
James
James•2y ago
GitHub
Proposed Changes to use the Vercel Build Output for Routing · Issue...
Hello, this issue outlines the proposed changes that I would like to make to how next-on-pages handles routing. The Vercel build output config contains the different steps taken during the routing ...
ysm
ysmOP•14mo ago
Wow Thanks you for quick reply Hi, @Better James . This is now supported, right?
James
James•14mo ago
Yes it should be supported for several months now 🙂
robmarscher
robmarscher•14mo ago
@Better James do you know if it can rewrite to an external destination (another CF worker hosting an API server)? I am getting 503 cloudflare network errors and unable to see much from the logs. The Pages docs on proxying redirects says it can only proxy relative URLs. So that makes me think it isn't supported for the NextJS rewrites. https://developers.cloudflare.com/pages/platform/redirects/#proxying
Redirects · Cloudflare Pages docs
To use redirects on Cloudflare Pages, declare your redirects in a plain text file called _redirects without a file extension, in the output folder of …
James
James•14mo ago
Next.js rewrites should work fine Not sure about rewriting to cloudflare hosted sites though since I only work on next-on-pages, not at cloudflare
robmarscher
robmarscher•14mo ago
Thanks a lot for the reply. It kept me from going down the wrong rabbit hole. There was an issue with the environment variable used for my rewrite destination. I read a bunch of your PR, the technical explanation of next-on-pages routing and looked at the unminified output files. The nextjs config rewrites are put into the built routing config in the filesystem phase. The fetch handler for the worker calls generateResponse after matching the route. If the matching route is a url, it uses fetch to get a response from the remote url. Makes sense. https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/templates/_worker.js/handleRequest.ts#L73
James
James•14mo ago
Yep, that sounds about right!
Want results from more Discord servers?
Add your server