API calls blocked after deploy? Check your CORS origins
Everything loads in the builder's preview. Then you open the live site on your own domain and sections are empty, a spinner never stops, or the signup button does nothing. Open the browser console and you see something like: Access to fetch at 'https://api.example.com/...' from origin 'https://yoursite.com' has been blocked by CORS policy.
Why it happens
Browsers block a page from reading responses from a different origin (a different domain, subdomain, protocol or port) unless that server says it's allowed. The server says so with the Access-Control-Allow-Origin response header.
Many APIs and backend functions are set up with a list of allowed origins. During building, that list often contains only the preview address, such as a .lovable.app, .bolt.new, .replit.dev or localhost URL. When you move to https://yoursite.com, your real origin isn't on the list, so the browser refuses to hand the response to your code.
Two details catch people out:
- Preflight. Requests that send JSON, an
Authorizationheader or methods like PUT and DELETE first send anOPTIONSrequest. If that OPTIONS request doesn't get the right headers back, the real request never happens. - A crash looks like CORS. If your function throws an error before it adds the headers, the browser reports a CORS error even though the real problem is a 500.
Step-by-step diagnosis
- Read the exact console message. It names the blocked URL and your origin. Copy both.
- Open the Network tab and reload. Find the failed request and any
OPTIONSrequest just before it. Check the status code and whetherAccess-Control-Allow-Originappears in the response headers. - Reproduce the preflight from a terminal:
curl -i -X OPTIONS https://api.example.com/endpoint -H "Origin: https://yoursite.com" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: content-type, authorization"
You want a 200 or 204 withAccess-Control-Allow-Origin: https://yoursite.comand the method and headers you asked for. - Compare origins character by character.
https://yoursite.comandhttps://www.yoursite.comare different origins. So arehttpandhttps. An origin never has a trailing slash or a path. - Check the server logs for the same moment. A crash there means you need to fix the error as well as the headers.
Fixes per builder and host
Supabase (used by Lovable, Bolt and many others)
Supabase's own database and auth APIs handle CORS for you. The usual culprit is an Edge Function. Each function must answer OPTIONS with the CORS headers and add the same headers to every response, including error responses. Include your live origin (or a shared allowed-origins list) in those headers.
Lovable
Ask Lovable: "My live domain is https://yoursite.com. Add it to the allowed origins in every backend function, return CORS headers on OPTIONS and on error responses, and show me the diff."
Bolt
Check whether the call goes to Supabase Edge Functions, Netlify Functions or a third-party API. For Netlify Functions, return the CORS headers in the response object and handle the OPTIONS method.
Replit
If your frontend and API run in the same deployment, call the API with a relative path such as /api/items. Same origin means no CORS at all. If they're separate, set the Express cors() middleware's origin option to your live domain, and register it before your routes.
v0 and Vercel
Next.js route handlers on the same domain don't need CORS. If the API lives on another domain, set headers in the route handler (and export an OPTIONS handler) or in the headers() section of next.config.js.
Cursor
Ask Cursor to "find every place that sets Access-Control-Allow-Origin or configures cors()", then add your live origin there.
Netlify and Cloudflare Pages or Workers
Static files are rarely the problem. For functions and Workers, the code must return the headers itself and answer OPTIONS.
A word of caution: don't "fix" it by echoing back any origin while also allowing credentials. That lets any website make logged-in requests as your users. List the origins you trust.
How to verify
- Redeploy, rerun the curl preflight and confirm your origin comes back.
- Open the live site in a private window with the console open. Load data, sign up and submit a form. No CORS errors should appear.
- Test both
wwwand the bare domain if both are reachable.
Keep it from coming back
- Keep allowed origins in one environment variable or config list, not copied into each function.
- Whenever you add or change a domain, update that list before switching DNS.
- Make error responses carry CORS headers too, so real errors show up as real errors.
- After each deploy, load the live site with the console open, not just the preview.
Previews often work because they run on an origin the backend already trusts. Your real visitors arrive on a different one.
FlowCanary's free check loads your live site in a real browser and reports console errors like CORS blocks, plus broken pages and links, with a copy-paste fix prompt for your builder.
