In short
"Blocked by CORS policy" is the error every full-stack beginner meets. It's not your API failing; it's the browser asking your server for permission, and your server not answering.
Browsers block requests from one origin (like localhost:5173) to another (like localhost:5000) unless the server allows it. The cors middleware tells the browser which origins are allowed.

Think of it like this
The guest list at the entrance
At a private party, the person at the rope checks a guest list before letting anyone in. The list is decided by the host, not the guest. With CORS, your server is the host and tells the browser which websites may read its responses.
Watch it happen
A preflight from shop.in to api.shop.in
OPTIONS /orders
1/5The page on shop.in wants to POST JSON to api.shop.in. Different origin, so the browser asks permission first.
The big ideas
What you need to know
Origin = scheme + host + port
http://localhost:5173 and http://localhost:3000 are different origins, which is why your dev setup hits CORS.
Browsers enforce it
CORS is a browser rule. curl, Postman and other servers ignore it completely.
Preflight for non-simple requests
JSON bodies, PUT, DELETE or custom headers trigger an OPTIONS request first. Your server must answer it.
Cookies need extra care
To send cookies cross-origin you need credentials: true on both sides, and the origin can't be the * wildcard.
See it in code
Walk through the code
1import cors from "cors";2 3const allowed = ["https://shop.in", "http://localhost:5173"];4 5app.use(cors({ origin: allowed, credentials: true }));1/2List exactly which frontends may read responses: production and your local Vite dev server.
The cors package answers preflights and echoes back the matching origin. Keep the list explicit; reflecting any origin with credentials is a real hole.
Save yourself the pain
Common mistakes
Oops
Thinking CORS protects your API from attackers.
Do this instead
It only controls which browser pages can read responses. Anyone can still call the API directly, so you still need auth.
Oops
Using origin: "*" with cookie-based login.
Do this instead
Browsers reject * with credentials. List your real frontend origins instead.
Your mission
Trigger and fix a CORS error
Quick check
Your API works in Postman but the React app gets a CORS error. What's going on?
Go deeper
- 1Allow only your frontend's URL instead of every origin.
- 2Set credentials: true on both sides when you send cookies.
- 3Read the CORS error in the browser console and match it to the missing header.
Also part of these roadmaps
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.