Postman is not subject to the browser’s same-origin rules. Your React page and Express API have different origins because their ports differ. A successful Postman request therefore does not prove that browser access is allowed.
Configure CORS on the Express server, before the routes that need it. For your local development setup, the example below allows the specific React origin. Install the maintained cors middleware first. Keep the API route you already have; the sample route just makes the configuration runnable.
Some requests trigger an OPTIONS preflight before the actual request. App-level cors middleware handles that case. Inspect both requests in the browser Network panel. The API must also return appropriate headers on error responses, or a CORS message can hide the underlying server error.
Do not use fetch with mode: "no-cors" to fix this: the resulting opaque response cannot be read as ordinary JSON. CORS is also not authentication and does not prevent non-browser clients from calling the API.
If you later use cookies across origins, the browser request needs credentials: "include" and the server needs credentials: true with an explicit permitted origin. Cookie SameSite/Secure behaviour and CSRF protection need separate consideration. Do not combine credentialed access with a wildcard origin.
See Express’s cors middleware documentation and MDN’s CORS guide. Use your real frontend origin in production rather than retaining localhost.
Prepared with AI assistance by Tai. Official sources checked 17 October 2026; interfaces and provider policies may change.
No comments yet.