-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for rewrites #5703
Comments
I think nextjs uses Vercel rewrites - which is also what I use in SvelteKit. I could be wrong though - I guess they have some sort of secondary solution in case you deploy a next app on a non-vercel platform? I quite like the idea of a rewrite from an endpoint, but I sort of also feel like this is outside of the scope of SvelteKit. Indicentally with adapter-node or similar you could do this sort of stuff within the node server. |
According to Vercel's docs, you can configure rewrites using a Is there some way that |
I got caught out by this, and I intended to document it, but I got distracted, so I apologise. adapter-vercel has no business dealing with rewrites, as these are handled by vercel itself. Instead, vercel needs to build the rewrites into the vercel filesystem api config generated by the adapter. Thus, to get rewrites into your deployed app if you are not building on vercel's platform but on your own CI: vercel build // merges rewrites into fs config |
Thanks for the quick response, @antony, but I'm not sure I understand. You say that running After doing some more research, I found that there is a way to integrate rewrite information into the filesystem api (apparently called the "Build Output API"). There is a transformer for turning the high-level, easy-to-use routing syntax from Based on this, I believe that the proper way of supporting rewrites for Vercel is to depend on the |
You don't need to. That's what vercel build does for you. I know it works for a fact as I rely on it in production. First run vite build, then vercel build, after each step compare the config file (I forget the name) in the .vercel output directory. |
After fiddling with it a bit more, it appears that my problem was due to a trailing slash! My {"rewrites": [{ "source": "/graphql/", "destination": "https://my.upstream.server/graphql/" }]} When I tried to deploy that, and make a request to When I tried changing my |
Found this issue out while trying to find a solution to my problem, I wanted to rewrite some sub-part of my SvelteKit site into another sub-domain. e.g. My rewrite rule works well in the I managed to work around it by making all my sub-domain pages So +1 for this feature! Until then, I hope this comment might help others |
Having the same issue as @francoislg. Any workarounds exist better than completely disabling CSR? |
Adding rewrites could potentially also solve one of the i18n use cases of translating the url |
I don't think this is an edge case. If someone wants to build something similar to Vercel Platforms in Svelte Kit, how can they do it now? |
{
"rewrites": [{
"source": "/:path*",
"has": [{
"type": "host",
"value": "api.lockie.dev"
}],
"destination": "/api/:path*"
}]
} subdomain rewrite doesn't work with SvelteKit |
Vercel rewrites happen before SvelteKit is executed, so SvelteKit has no bearing on whether this type of rewrite works or not. It sounds like something is wrong with your vercel setup / rewrite. Certain types of rewrite don't work on certain plans with Vercel, as far as I remember. |
@Rich-Harris According to the current implementation of the reroute hook, we can't implement dynamic checks, like checking whether the incoming request is from a custom domain that is registered. We still do not have a hook level rewrite like in Next that can help us build something like Vercel Platforms |
Describe the problem
Probably kind of a huge undertaking, but it would be great to have rewrite support in SvelteKit similar to what Next.js can do.
The big hurdle for me comes when trying to convert existing PHP sites to SvelteKit. In PHP we'd have .htaccess to handle rewrites, but JS would require either the framework handling it, or a reverse proxy handling it beforehand (which is not helpful during development).
Static uploads are also something I'd love to be able to perform rewrites for. There's one site in particular I cannot convert because it acts as a monorepo for several other websites that share one common uploads directory separated by domain names.
For instance, when
/example.png
is accessed, PHP is rewriting it to/uploads/<domain>/images/example.png
, which I believe is not possible to do in SvelteKit currently. Vite can change the assets path, but it is not dynamic.hooks.js
can redirect, but ideally I would like to abstract the path away from the user so they never see the true source.Describe the proposed solution
Implement something similar to Next.js' rewrite solution, or the ability to rewrite from
handle
orload
functions as opposed to redirect.Alternatives considered
Apart from having a reverse proxy in front, I don't believe there is a true solution currently.
The
handle
function can perform a redirect, but not a rewrite.Under certain circumstances you could kludge up a
[...catchall].svelte
to redirect the requests, but also is not rewriting.Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: