I’m running into a similar issue unfortunately. My Netlify site is running on a subdomain, I need the functions to be accessible from the base domain. Here’s what I have in my _headers that I downloaded from a deploy:
/*
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
/api/*
Access-Control-Allow-Origin: https://basedomain.com
Access-Control-Allow-Methods: PUT, POST, OPTIONS
Vary: Origin
/static/*
Cache-Control: public, max-age=31536000, immutable
But when I try the URL with Curl, I don’t get any of those headers:
❯ curl -svo /dev/null https://api.basedomain.com/api/submit-contact 2>&1 | egrep "< "
< HTTP/2 200
< cache-control: no-cache
< server: Netlify
< x-nf-request-id: 01FE4JFKT0BTAC6AYTWRFHNW00
< age: 1
< date: Fri, 27 Aug 2021 19:48:13 GMT
< content-length: 73
< content-type: text/plain; charset=utf-8
<
However, funny enough, if I try a resource in /static/*, the headers work as intended:
❯ curl -svo /dev/null https://api.basedomain.com/static/animage.png 2>&1 | egrep "< "
< HTTP/2 200
< accept-ranges: bytes
< content-length: 36766
< content-type: image/webp
< date: Fri, 27 Aug 2021 19:58:08 GMT
< etag: "af3a6a638a2c34993f3c92e3ae74a7bf-ssl"
< referrer-policy: same-origin
< strict-transport-security: max-age=31536000
< server: Netlify
< age: 0
< cache-control: public,max-age=31536000,immutable
< x-nf-request-id: 01FE4K1SR44WE1C56Y2VAZPZMA
< x-content-type-options: nosniff
< x-frame-options: DENY
< x-xss-protection: 1; mode=block
<
I’ve tried moving the rules for /api/* into the root one, but that had no effect. It doesn’t seem like I have mistakes in my headers, I’ve double-checked, but I’m completely out of options here.
UPD 1: After some more investigating, it seems that _headers doesn’t have any effect on functions. I can’t find any other information on that, it’s like no one had run into this issue.
UPD 2: This is just an affirmation of the first update. I added the access-control headers into the functions themselves and that worked. Probably should either mention that somewhere or take _headers into account for functions as well.