getting cors errors in vite
‘access-control-allow-origin’ header being properly set to ‘*’
Using golang, vite, react and fetch api. Keep getting cors errors when try to fetch port 3000 from 5173. But when directly accessing the api in my dev api client (thunder client extension in vscode), the ‘access-control-allow-origin’ is properly set to “*”.
When trying to fetch data in react, it seems that fetch just returns instantly, without even making the request to the server, when checking the server log, there was no requests made, but the react client just gives out the cors error whatsoever.
I’ve tried to use other backend servers, like nestjs. The result is the same: the ‘access-control-allow-origin’ header is properly set to ‘*’, but the client keeps giving the same error.
I’ve also tried to set other headers that are related to cors, such as ‘access-control-allow-methods’ and ‘access-control-expost-headers’, does not work still.
Any help would be appreciated
Zhou Xudong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.