1

Access-Control-Allow-Origin is properly set to '*';

Tried using nestjs as backend with the same address, works perfectly fine.

But when using gin, although the header is properly set, still get the error.

What is even more confusing, is that after fetching to the gin server, when I switch back to the nestjs server, it gives me the cors error again. No matter how I refetch.

I have to switch browser from edge to chrome. But as soon as I make a request to the gin server, the error just pop up and won't leave even after switching the backend to nestjs.

Error: localhost/:1 Access to fetch at 'http://localhost:3000/api/record' from origin 'http://localhost:5174' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Any help would be appreciated

1
  • Depending on the client's request, headers other than Access-Control-Allow-Origin may be required in the response for the CORS handshake to be successful. But what error message are you getting? Edit your question and add it there (as text, not as a picture).
    – jub0bs
    Commented May 11 at 20:24

1 Answer 1

1

Solved.

It's a problem of "...url" != "...url/" conbined with this annoying cors caching mechanism.

In go, when using a group to get a group router, then use METHOD("/", func...), would make the url be "...url/" but not "...url", and after getting the cors error, you have to clear the browser cache to make it make a request to verify again.

Visible frustration, why does the browser cache the cors result?

Not the answer you're looking for? Browse other questions tagged or ask your own question.