My golang function does not redirect anywhere when called by a javascript fetch function. This is an extension of my previous question which was too broad. Facebook Oauth CORS error
This is my javascript fetch function calling the golang api.
let config = {
method: 'GET',
}
fetch("http://localhost:7001/testFunction", config).then(response => {
...
This is my golang function trying to redirect afterwards
func testfunc(w http.ResponseWriter, r *http.Request) {
http.Redirect(w,r,"https://www.facebook.com/dialog/oauth?..", 302)
http.Redirect(w, r, "http://localhost:7001/", 302)
http.Redirect(w, r, "http://google.com/", 302)
}
The outcome is supposed to be that the page redirects to a page outside the domain, but I consistently get this error on network.
Fetch API cannot load http://google.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I cannot use no-cors mode because I need to redirect to that page or even retrieve a json back.
I made sure the golang server headers were correct and allowed the javascript origin (localhost:3000). And I made sure that the oauth api on facebook allowed the golang server domain (localhost:7001). Yet the redirects are always blocked when accessing domains outside of the localhost domain scope.