Menu

Fixing "No 'Access-Control-Allow-Origin' header": a 5-minute CORS checklist
📰

Fixing "No 'Access-Control-Allow-Origin' header": a 5-minute CORS checklist

DEV Community: javascript·Gerald Mitchell·3 days ago
#qpAPSFYl
#devtojavascript#devto#dev#access#cors
Reading 0:00
15s threshold

You call your API from the frontend and the console shows:

Access to fetch at 'https://api.example.com/data' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Enter fullscreen mode

Exit fullscreen mode

The request often reached your server and succeeded . The browser just refused to hand the response to your JavaScript. CORS is enforced by the browser, so the fix almost always lives on the server , not in the fetch call.

Step 1: Is it a preflight?

The browser sends an OPTIONS request first if any of these are true:

the method isn't GET, HEAD or POST

you send Content-Type: application/json (yes, really)

you send custom headers such as Authorization

Open DevTools > Network, tick "All", and look for an OPTIONS request.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.