You can’t set a header on a proxied redirect.
[[redirects]]
from = "/api/*"
to = "https://api.example.com/:splat"
status = 200
headers = {Access-Control-Allow-Origin = "*"}
This doesn’t work, although the docs say it should:
- https://www.netlify.com/blog/2017/10/17/introducing-structured-redirects-and-headers/#custom-headers-in-proxy-redirects
- https://www.netlify.com/docs/redirects/#structured-configuration
The redirect works, but the CORS header isn’t added.
Adding a headers block just for this route also doesn’t work:
[[headers]]
for = "/api/*"
[headers.values]
Access-Control-Allow-Origin = "*"
However interestingly if you apply this rule to everything:
[[headers]]
for = "*"
[headers.values]
Access-Control-Allow-Origin = "*"
The header gets set on static pages served by Netlify.
However proxied redirects don’t get the header.
This is causing issues for me because I can’t use my API endpoint for development or prerendering without a CORS header.