_headers file and Astro
Hi all, new to CF Pages and Astro (static generated). Even so, I've managed to create a nice blog site pretty quickly.
However, I want to make use of some custom headers but I can't figure out how to make the Astro build process create a file called
_headers
in the dist root folder. If I create a /src/pages/_headers.js
, the Astro build ignores it. If I rename to headers.js
it produces the correct output but with the wrong name,
Can anyone guide me to the correct process please? Thanks.5 Replies
Files under
/src/
are processed by Astro. For _headers
you want it to be used as-is as a static asset, so it should be in your directory for static assets, which is /public/
by default.Hi, thanks for your response. However, the
_headers
file isn't a static asset, it is a private file used by Cloudflare Pages and most certainly should not be publicly available. I just can't work out how to get this to work with Astro.The
_headers
file goes at the top level of your output folder. The way you do that in Astro is to put it in the static asset folder, so it is copied as-is. Pages will pick it up from the output folder.Ah, thank you! That isn't at all clear from the docs. I will give that a go. Many thanks again.
It has worked, thanks again.