-
Notifications
You must be signed in to change notification settings - Fork 11
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
Astro: Redirects cause adapter to fail #3094
Comments
How would this work?
Client hits the redirect URL, we detect it and If so, that seems like the right choice because there's not really anything for us to process on a redirect. Arcjet would likely run again on the next request anyway. |
With the Vercel adapter, the redirects are just added to the |
Makes sense. Then warning probably doesn't add much since there's nothing for us to protect. A redirect should take priority over executing any code because the real relevant context is wherever the redirect destination is. |
I guess I'm worried that someone will add arcjet in their middleware, generate a website in static mode, and think their routes are protected via bot protection. Adding the warning would at least alert them during generation. Alternatively, I could design the reporting functionality during build 🤔 This could also be a problem in an Astro component if it is marked as prerendered since |
The more I think about things like the above, the more I think we need to provide a utility function like |
This doesn't actually seem to be a problem with If we don't want to call this a bug with the Vercel adapter, then it is just a problem specific to that adapter and makes me lean even further to adding an opt-in workaround just for that platform. |
I set up an example with the Vercel adapter and it works completely normally. This leads me to believe the bug is within Starlight 😬 |
I can't actually figure out where this would happen in Starlight and I traced the actual failure into Astro; however, I don't know what combination of Vercel Adapter, Starlight, Arcjet, or other integrations cause this. Instead, I'm working on a feature request into Astro that we can recommend users leverage. |
Astro PR: withastro/astro#13143 |
It seems that redirects defined in
astro.config.mjs
cause our adapter to fail. This is due to thecontext.isPrerendered
flag being set tofalse
yetcontext.clientAddress
throws when accessed. This generally makes sense because a redirect doesn't produce a static page itself.Astro doesn't seem to have anything like
isRedirect
on the context but you can discover redirects during the build process. I experimented with using codegen to make anisDynamic
function that consumed the discovered redirects but I'm not sure I'm happy with users needed to import the utility explictly.Instead, we could use this generated logic to warn and produce an
Allow
decision on static pages. Alternatively, we could produce anError
decision like we do when IP isn't defined. I'm not sure which is better.The text was updated successfully, but these errors were encountered: