Browser

Access to XMLHttpRequest blocked by CORS policy

CORS Policy Blocked

The browser blocked a cross-origin request because the server didn't send appropriate CORS headers.

Common Causes

Fixes

  1. 1. Add CORS headers on server
    Access-Control-Allow-Origin: https://yourdomain.com
    Access-Control-Allow-Methods: GET, POST, OPTIONS
  2. 2. Handle preflight
    if (req.method === 'OPTIONS') return res.sendStatus(204);
  3. 3. Use a proxy in development
    // next.config.js: rewrites to backend

Still not fixed?

Related Errors

DuskTools That Might Help

All Errors