The browser rejects the CORS preflight because the OPTIONS reply is not a 2xx
Response for preflight does not have HTTP ok statusShort answer
Before some cross-origin calls the browser sends an OPTIONS preflight and treats any answer outside 200 to 299 as a network error. Run the same OPTIONS request with curl to read the status. Usually the API routes or an auth check reject OPTIONS. Answer it early with CORS middleware, or proxy in development.
Fix it fast
1Find out which cause you have
Send the preflight yourself and read the status line. Use your real API URL, the origin of your Angular app, and the method and headers your code uses.
curl -i -X OPTIONS https://api.example.com/orders \ -H "Origin: http://localhost:4200" \ -H "Access-Control-Request-Method: POST" \ -H "Access-Control-Request-Headers: content-type,authorization"2Match what you see, then jump to its fix
- 1
curl prints HTTP/1.1 401, 403, 404 or 405 for the OPTIONS request, while the same URL works with GET or POSTAn auth guard or router answers OPTIONS with 401, 403, 404 or 405Fix - 2
curl returns 404 or a login page for OPTIONS even though cors() is installedThe cors option preflightContinue hands OPTIONS to a later handlerFix - 3
The API belongs to another team or a vendor and its OPTIONS reply is not 2xxYou cannot change the API server during developmentFix
- 1
What does the error look like?
Response for preflight does not have HTTP ok statusThe request in the Network tab is an OPTIONS call with a red status, and the real GET or POST never appears
Cause 1 of 3
An auth guard or router answers OPTIONS with 401, 403, 404 or 405
1Check
A preflight never carries credentials, so an auth check that runs before CORS rejects it. A route table that only lists GET and POST has no OPTIONS handler and returns 404 or 405. The Fetch standard turns any preflight answer outside the 200 to 299 range into a network error.
curl -s -o /dev/null -w "%{http_code}\n" -X OPTIONS https://api.example.com/orders \
-H "Origin: http://localhost:4200" -H "Access-Control-Request-Method: POST"2Fix
Register the CORS middleware before the auth middleware and before the routes, so it ends the preflight with a success status. In the Express cors package, app-level use already handles preflight for every route.
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors({ origin: 'http://localhost:4200' }));
// auth middleware and routes come after this line3Verify
The same curl should now print a 2xx status with Access-Control-Allow-* headers.
curl -i -X OPTIONS https://api.example.com/orders \
-H "Origin: http://localhost:4200" -H "Access-Control-Request-Method: POST"Confirmed by fetch.spec.whatwg.org
Cause 2 of 3
The cors option preflightContinue hands OPTIONS to a later handler
1Check
With preflightContinue enabled, the cors package does not end the preflight itself and passes the request on to the next handler. The default is false. Search the code for the option.
grep -rn "preflightContinue\|optionsSuccessStatus" src/2Fix
Remove preflightContinue, or add an explicit OPTIONS handler that returns a success status. The default status for a successful preflight is 204.
app.use(cors({
origin: 'http://localhost:4200',
preflightContinue: false,
optionsSuccessStatus: 204
}));3Verify
Repeat the OPTIONS request with curl and confirm the status.
curl -i -X OPTIONS https://api.example.com/orders -H "Origin: http://localhost:4200" -H "Access-Control-Request-Method: POST"Confirmed by github.com
Cause 3 of 3
You cannot change the API server during development
1Check
CORS is enforced by the browser only. If the Angular dev server calls the API through its own proxy, the browser sees one origin and sends no cross-origin preflight.
grep -n "proxyConfig" angular.json2Fix
Create src/proxy.conf.json, point the serve target at it, call /api/... from the app, and restart ng serve.
// src/proxy.conf.json
{
"/api/**": {
"target": "https://api.example.com",
"secure": true
}
}
// angular.json, serve target options
"proxyConfig": "src/proxy.conf.json"3Verify
Restart the dev server and call the proxied path; the Network tab should show no OPTIONS request.
ng serveConfirmed by angular.dev
How do I stop it coming back?
- Keep CORS as the first middleware, ahead of authentication and routing.
- Add an automated check that sends an OPTIONS request to each public API route and expects 2xx.
- List the allowed origins explicitly per environment instead of editing them in production by hand.
- Use the dev proxy only for development; production still needs the real CORS headers on the API.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
The browser blocks your API response: no Access-Control-Allow-Origin header
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.example.com/orders. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
The browser received the response but refused to hand it to your script, because it did not carry an Access-Control-Allow-Origin header naming the page's origin.
4 causes, each with a fixWeb apps
Axios sends no cookie to an Express API even with withCredentials set to true
The login response has a Set-Cookie header, but the browser stores nothing
withCredentials only tells the browser to attach cookies.
4 causes, each with a fixWeb apps
The cors-anywhere.herokuapp.com demo proxy stopped working
Missing required request header. Must specify one of: origin,x-requested-with
The public cors-anywhere.herokuapp.com server is only a demo, is rate limited, and since February 2021 requires an opt-in.
2 causes, each with a fixWeb apps
A public website cannot reach your local dev server: local network request blocked
Look for and connect to any device on your local network
Chrome treats a request from a public website to localhost or a private IP as a local network request.
3 causes, each with a fixWeb apps
CORS fails when you open an HTML file straight from disk
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///
A page opened from disk has an opaque origin, so browsers treat every request it makes as cross-origin, and CORS only works over http or https.
3 causes, each with a fixWeb apps
Firefox blocks a cross-origin request even though the CORS headers are set
Reason: Multiple CORS header 'Access-Control-Allow-Origin' not allowed
Firefox puts a Reason in the console message, and that text is the diagnosis.
5 causes, each with a fix