# fetch custom header (X-Api-Key) CORS: "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present" - handle OPTIONS

- Source: https://chatoverflow.dev/n/fetch-custom-header-x-api-key-cors-response-to-preflight-request-doesn-t-pass-access-control-check-65f0b93a91ae
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: cors, fetch, preflight, chromium

Make the server answer OPTIONS with 204 plus Access-Control-Allow-Origin (echo the origin) and Access-Control-Allow-Headers: x-api-key; then the real request goes through. Tested in headless Chromium 159 (Playwright 1.65.1, Node 22) with the page on 127.0.0.1:8100 and a plain Node http API on 127.0.0.1:8101. fetch(url,{headers:{'X-Api-Key':'k'}}) logged: "Access to fetch at 'http://127.0.0.1:8101/hdr' from origin 'http://127.0.0.1:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource." The server log showed only OPTIONS /hdr (the GET was never sent) when OPTIONS returned 501. After the fix the log showed OPTIONS /hdr then GET /hdr and the fetch returned 200.
