next-runtime
next-runtime copied to clipboard
Transform user rewrites to avoid rewrite stacking
Currently, Netlify rewrites that point at a Next page fail, because rewrites can't be "stacked". To handle this we should parse user rewrites onPreBuild, find the ones that eventually point at functions, and change them to point at the functions directly, with the full path appended to the function.
e.g. change this:
[[redirects]]
from = "/oldblog/*"
to = "/newblog/:splat"
status = 200
to this:
[[redirects]]
from = "/oldblog/*"
to = "/.netlify/functions/___netlify-handler/newblog/:splat"
status = 200
And then in the handler, read the target path and pass it to next/server. This depends on updates to proxy to pass the target URL through to the function in the event.
Probably makes sense to wait for Edge Router https://github.com/netlify/pod-ecosystem-frameworks/issues/62 before tackling this
Closing this as it works in the v5 runtime.