-
Notifications
You must be signed in to change notification settings - Fork 511
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(cloudflare-pages): handle assets only for get requests #968
Conversation
Codecov Report
@@ Coverage Diff @@
## main #968 +/- ##
=======================================
Coverage 67.34% 67.34%
=======================================
Files 60 60
Lines 6073 6073
Branches 680 680
=======================================
Hits 4090 4090
Misses 1974 1974
Partials 9 9 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
const asset = await ctx.next(); | ||
if (asset.status !== 404) { | ||
return asset; | ||
if (ctx.request.method === "GET") { |
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.
I think we might also support for HEAD
if (ctx.request.method === "GET") { | |
if (ctx.request.method === "GET" || ctx.request.method === "HEAD") { |
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.
No, that is not allowed by Cloudflare either. You can confirm locally by building a nitro project and performing a HEAD request against it:
Before making this PR, I also tried with OPTIONS, as another promising one which might be useful for prerendered API routes, but unfortunately it's not allowed either.
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.
Hmm thanks for confirming.
This is strange because normal worker has fine gained API to control caching headers via head. (and i suppose would be useful for cors and options)
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.
It would indeed be useful. Maybe they can add more options down the line to configuration via _routes.json
?
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.
Okay, let's revise it later GET is good enough.
π Linked issue
closes #796 - this is a remake as I had no permission to push changes to the branch (make sure to give credit when merging)
resolves #497
resolves #787
β Type of change
π Description
CF will throw a 405 error when fetching assets with a non-GET request. I think we can guard them here safely, with the note that we should also merge #965 alongside this to avoid hitting endpoint for known assets/asset prefixes.
π Checklist