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.
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.
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.
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.
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.
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