Custom Headers for Cloudflare Pages

Screenshot%20from%202019-08-27%2015-04-37

2 Likes

https://developers.cloudflare.com/pages/how-to/add-custom-http-headers

Needs updating, FYI.

Alerted the team.

2 Likes

Or create a PR, like @Walshy

2 Likes

I’m not sure how they want to fix it, though. It’s a lot more than a typo.

The page itself is still useful since _headers is not complete. Just needs to be updated with the fact that _headers exists, imo.

Although we don’t support all of its features, we’ve modeled this matching engine after the URLPattern specification which was recently shipped with Chrome 95. We plan to be able to fully implement this specification for custom headers once URLPattern lands in the Workers runtime

For instance, I want certain headers sent on all assets (png, jpg, etc.) so I tried \.(png|jpg)$ but that did not do the trick. It didn’t produce a build error either (which is a feature I’d asked for, so :shrug:).

Edit: Also tried .(png|jpg)$ and *.(png|jpg)$ just for fun.

Have you tried doing two different matches?

/static/*.jpg
   Access-Control-Allow-Origin: *
/static/*.png
   Access-Control-Allow-Origin: *

Depends on how greedy the match is.

I thought about it but did not. I’ve got a few headers (and exceptions) so my _headers file would be unnecessarily long and unwieldy. Just going to wait until URLPattern is available fully. Any day now…

Good suggestion though for those who might be able to use it. :slight_smile:

Nice! I had this dragged around from Netlify, and tbh, I found Workers quite the learning curve (which I will still pursue), but I really wanted to be able to use my old config file. And now, here it is. Thanks!