-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: append prerendered redirects to _redirects
file
#12199
Conversation
🦋 Changeset detectedLatest commit: be8b4bb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
_redirects
file
If the target of redirect is a small file, it gets included in the redirects as data:base64 URL (not valid in Cloudflare's eyes), is there a way to prevent it, apart form changing Vite's inline limit? Due to the latest change, client gets served the HTML/JS redirect instead of being redirect by the server. |
Not that I know of. Your best bet is to add a predicate to the
Which change are you referring to? Can you elaborate? |
The predicate might be a good thing to be mentioned in the docs if this PR gets merged.
I'm referring to my own commit which excludes the redirected path from being processed by the worker |
I'm not sure if I understand. Isn't the _redirects rule serving the redirect instead of the HTML/JS file? |
Yes, exactly, but when the files gets inlined, it gets inlined inside the |
Weird, I wasn't able to reproduce that. When I followed the +server.js example from the PR description, there simply wasn't any HTML file reproduced and the _redirects file was empty. Maybe we can throw an error with instructions on how to fix this if one of the redirect locations is a base64 string (I'd open a new issue and PR for this if the inlined base64 string causes the prerendered redirect to disappear because it sounds different from the scope of this PR). Side note: we should probably add a check to see if there are any prerendered redirects before writing to _redirects: + if (builder.prerendered.redirects.size > 0) {
writeFileSync(`${dest}/_redirects`, generate_redirects(builder), { flag: 'a' });
+ } |
Thank you! |
* feat: Generate static _routes in Cloudflare adapter * Update .changeset/ten-shirts-add.md * fix: add comements and newline in generated _redirects file * fix: exclude redirect paths from cloudflare * fix: check if there are redirects before writing * Fix formatting --------- Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Makes Cloudflare Pages adapter generate a static
_redirects
file in build output.This way the redirects happen on server and don't have to be a client-side HTML file as it is now.
It simply collects redirects from
builder.prerendered.redirects
, so I am not sure how reliable that is?My example purpose is that I have following
+server.ts
file:Normally the adapter generates a
__data.json
and an .html file that redirects the user there (which still happens, I didn't change that), but I need that redirect to happen on server, so that thefile.json
file is served.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits