-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fix(routing): emit error for forbidden rewrite #12339
base: next
Are you sure you want to change the base?
Changes from all commits
e4cf625
2544f5e
588cc95
047e6de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Now Astro emits an error when `Astro.rewrite` is used to rewrite an on-demand route with a static route, when using the `"server"` output. | ||
|
||
This isn't possible because Astro can't retrieve the emitted static route at runtime, because it's served by the hosting platform, and not Astro itself. | ||
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1260,6 +1260,23 @@ export const RewriteWithBodyUsed = { | |||||||||||||
'Astro.rewrite() cannot be used if the request body has already been read. If you need to read the body, first clone the request.', | ||||||||||||||
} satisfies ErrorData; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* @docs | ||||||||||||||
* @description | ||||||||||||||
* `Astro.rewrite()` can't be used to rewrite an on-demand route with a static route, when using the `"server"` output. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
* | ||||||||||||||
*/ | ||||||||||||||
export const ForbiddenRewrite = { | ||||||||||||||
name: 'ForbiddenRewrite', | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting that there may eventually be other kinds of "forbidden" rewrites, so not sure whether you want to add more context like |
||||||||||||||
title: "Can't use `Astro.rewrite()` from a on-demand route to static route with 'server' output.", | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
typo fix here at the very least, but in fact, see suggestion for title below also. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the very least, the typo needs to be corrected to an on-demand route. Also noting that this is a little longer than other titles are, and almost repeats the docs text exactly. So this could instead be a shorter thing like:
and then let the docs text explain what's happening? |
||||||||||||||
message: (from: string, to: string, component: string) => | ||||||||||||||
`You tried to rewrite the on-demand route '${from}' with the static route '${to}', when using the 'server' output. \n\nThe static route '${to}' is rendered by the component | ||||||||||||||
'${component}', which is marked as prerendered. This is a forbidden operation because during the build the component '${component}' is compiled to an | ||||||||||||||
HTML file, which is can't be retrieved at runtime by Astro.`, | ||||||||||||||
Comment on lines
+1273
to
+1275
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
hint: (component: string) => | ||||||||||||||
`Add \`export const prerender = false\` to the component '${component}', or use a Astro.redirect().`, | ||||||||||||||
} satisfies ErrorData; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* @docs | ||||||||||||||
* @description | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
return Astro.rewrite("/forbidden/static") | ||
export const prerender = false | ||
--- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
export const prerender = true | ||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.