Open 5a3o opened 5 years ago
I tested your code and it worked fine on both 'http://localhost:8080/api/v1/application' and 'http://localhost:8080/api/v2/application'. Have I covered your test scenario correctly?
may you change
c.Writer.Header().Set("Access-Control-Allow-Origin", "http://localhost:3000")
to
"c.Writer.Header().Set(Access-Control-Allow-Origin", c.Request.Header.Get("Origin")
If in development enviroment, you can try to running the local test with
("Access-Control-Allow-Origin", "*")
.
I had the same issue,
What's the root cause?
It appears this happens when the auth is missing or incorrect. Your function isn't evaluated and it doesn't write out the header.
Description
CORS issue when Basic Auth is enabled on a group Added two routes,
Error Message On Client: Access to XMLHttpRequest at 'http://localhost:8080/api/v2/application' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Screenshots
Code Attached
main.txt
CODE