Static Asset - Override Headers
Hi all,
I have a scenario in which I want to host part of the website from Cloudflare Static Assets, part from origin server. Additionally for a scenario in which I serve static html pages from Cloudflare Static Assets, I want to dynamically set http headers based on some query parameters.
I see 2 issues here:
1) If Static Assets is serving file, I can's see my worker logs via Cloudflare Dashboard,
2) It seems that I am unable to modify headers of the response from
await env.ASSETS.fetch(path)
Am I missing something? Or is this a limitation?3 Replies
You will need to run the Worker first so then you can
env.ASSETS.fetch
, then modify and serve
You can do that with the serve_directly option - https://developers.cloudflare.com/workers/static-assets/routing/#invoking-worker-script-ahead-of-assetsthank you, will check in the evening
❤️
Do note however that by doing this, you will incur a Worker invocation for the Asset request, making it no longer free. Hopefully this is an improvement we can get to the Assets platform in future with
_headers
or similar so we don't have to invoke a Worker just to add a header, like with Pages.