What is CORS?
The red "blocked by CORS policy" line in your console is not your frontend's fault and not a bug in the browser. It is the server not yet saying your site is allowed in.

Key takeaways
- Browsers block scripts from reading responses from another origin unless that server answers with permission headers.
- CORS is fixed on the server you are calling, never in the frontend; a wildcard origin is risky for anything with user data.
- CORS only applies in browsers. Server code and mobile apps are not subject to it, so it does not protect an API on its own.
Behind the acronym, CORS (Cross-Origin Resource Sharing) is a browser security rule: a page loaded from one website can only read responses from a different website if that other site explicitly allows it, by sending back headers such as `Access-Control-Allow-Origin`. When you see "has been blocked by CORS policy" in the browser console, the server you called did not grant that permission.
An everyday example: the doorman's guest list
Picture an apartment building with a doorman. Anyone can walk up and ask for a package to be delivered to a resident. But the doorman only hands a reply back to visitors on the resident's guest list. Your browser is the doorman. A script from `myshop.startbase.app` asks `api.example.com` for data. The request goes out, but unless the response says "myshop.startbase.app is on my list," the browser refuses to hand the answer to the script.
An origin is the scheme, domain and port together. `https://myshop.com` and `https://www.myshop.com` are different origins, and so are `http://localhost:3000` and `http://localhost:5173`. That surprises people more than anything else about CORS.
The preflight request
For requests that could change data (a POST with JSON, a PUT or DELETE, or anything carrying an `Authorization` header), the browser first sends an automatic OPTIONS request asking "may I?" The server must answer with which origins, methods and headers it accepts. If the function you wrote only handles POST and returns an error for OPTIONS, every real request fails before it starts, even though the POST code itself is fine.
The right fix (and the wrong ones)
- Right: have the server you are calling return `Access-Control-Allow-Origin` with your exact site addresses, answer OPTIONS requests, and list the headers your app sends.
- Risky: `Access-Control-Allow-Origin: *` lets any website's scripts read the response. Acceptable for truly public data, a bad idea for anything tied to a signed-in user.
- Wrong: browser extensions that disable CORS. They make it work on your machine and nowhere else.
- When you do not control the server: call the third-party API from your own backend function instead of from the browser. That also keeps its key out of the frontend.
Why it matters when building with Startbase
A published Startbase app lives at one address (a `*.startbase.app` address or your custom domain) while its backend functions live at another, so calls from the browser to an edge function are cross-origin. The agent writes those functions and checks its work, but CORS errors still turn up when an address changes, for example after you connect a custom domain and the function only allows the old one. The fastest fix is to give the agent the exact console line.
After connecting my custom domain, the browser console shows: "Access to fetch at the send-invite function from origin https://www.myclub.com has been blocked by CORS policy." Allow my published address, my custom domain and the preview origin in that function, answer OPTIONS preflight requests, and do not use a wildcard origin.
For more on reading console errors, see how to fix bugs with AI.
Common confusions
- CORS does not secure your API. It only stops other websites' scripts from reading responses in a browser. A script on a server, or curl, ignores it entirely. Real protection is authentication and authorization.
- The request often still reached the server. A blocked simple request may have run; the browser just hid the answer. Do not assume nothing happened.
- Mobile apps do not hit CORS because there is no browser enforcing it, which is why the same call can work in Expo Go and fail on the web version.
Frequently asked questions
Why does my API work in Postman but not in my app?
Postman is not a browser, so it does not enforce CORS. The browser does, and it needs the server to send the right Access-Control headers for your site's origin.
Can I fix a CORS error in my frontend code?
No. The permission has to come from the server being called. From the frontend, the only workaround is routing the call through a backend you control.

