TechnicalCollectible prompt
Fix CORS errors without opening your API to everyone
Act as a senior web engineer. My {{tech_stack}} front end can't call my API or server function, and the browser shows a CORS error. Here it is, exactly as the console printed it: {{error_message}}
Gather evidence first:
- The full console message; it names what's missing, such as no Access-Control-Allow-Origin header, or a preflight that failed
- In the network tab, both requests if there are two: the OPTIONS preflight and the real one, with status codes and response headers
- Whether the same request works from curl. If it does, the server works and only the browser's cross-origin rules are failing
- Which origins fail: localhost, preview URLs, the live domain, www versus the bare domain
Likely causes for this symptom:
1. The server returns an error (500, 401 or 404) without CORS headers, so the browser reports CORS instead of the real error. Check the server logs first
2. The OPTIONS preflight isn't handled, or auth middleware rejects it for having no token
3. The allowed origin doesn't match exactly: protocol, www, port or a trailing slash
4. Cookies or auth headers sent with a wildcard origin, which browsers reject
5. A header such as Authorization, or a JSON content type, triggers a preflight the server doesn't allow
6. The call shouldn't be cross-origin at all: a wrong base URL, or a same-origin rewrite or proxy would be simpler
Confirm the cause, then make the smallest fix: an explicit list of allowed origins from an environment variable, only the methods and headers actually used, and preflight handled before auth. Never use a wildcard origin with credentials, echo back any origin, or call a third-party API with a secret key from the browser. Add a test for one allowed and one disallowed origin, and explain CORS in two plain sentences.
Technicalnvoka.com/library/nvoka-fix-cors-errors-without-opening-your-apiScan to open
Technical
Fix CORS errors without opening your API to everyone
Read the real CORS error, find which header or request is wrong, and allow only the origins you trust.
Curated by Nvoka
CursorClaude CodeCodexGitHub Copilot
Make it yours
Fill in the blanks and change any word. Only your copy changes, never the card.
Fill in the blanks
0 of 2 filledYour prompt
Act as a senior web engineer. My {{tech_stack}} front end can't call my API or server function, and the browser shows a CORS error. Here it is, exactly as the console printed it: {{error_message}}
Gather evidence first:
- The full console message; it names what's missing, such as no Access-Control-Allow-Origin header, or a preflight that failed
- In the network tab, both requests if there are two: the OPTIONS preflight and the real one, with status codes and response headers
- Whether the same request works from curl. If it does, the server works and only the browser's cross-origin rules are failing
- Which origins fail: localhost, preview URLs, the live domain, www versus the bare domain
Likely causes for this symptom:
1. The server returns an error (500, 401 or 404) without CORS headers, so the browser reports CORS instead of the real error. Check the server logs first
2. The OPTIONS preflight isn't handled, or auth middleware rejects it for having no token
3. The allowed origin doesn't match exactly: protocol, www, port or a trailing slash
4. Cookies or auth headers sent with a wildcard origin, which browsers reject
5. A header such as Authorization, or a JSON content type, triggers a preflight the server doesn't allow
6. The call shouldn't be cross-origin at all: a wrong base URL, or a same-origin rewrite or proxy would be simpler
Confirm the cause, then make the smallest fix: an explicit list of allowed origins from an environment variable, only the methods and headers actually used, and preflight handled before auth. Never use a wildcard origin with credentials, echo back any origin, or call a third-party API with a secret key from the browser. Add a test for one allowed and one disallowed origin, and explain CORS in two plain sentences.