I am trying to redirect to another URL after a POST FETCH call.
fetch("/", { method: "POST", redirect: "follow" })
.then((res) => {
console.log(res);
})
.catch(function (err) {
console.info(err + " url: ");
});
The backend is an Express endpoint with a simple redirect like so,
var cors = require('cors');
app.use(cors());
app.post("/", (req, res) => {
res.redirect("https://google.com");
});
I want to change window.location
after fetch call resolves the promise but the call fails with,
Access to fetch at 'https://google.com/' (redirected from 'http://localhost:3000/') from origin 'http://localhost:3000' 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.
I understand that the error is because I am accessing google.com which has CORS enabled and I am not allowed to fetch data, but I just want to be able to redirect to that URL. Is there a different way I should be doing this?