After sending a POST request to my Node backend I'd like to redirect the user to another site using e.g. a Location header in the server response.
I'm sending the POST request to my server with Axios using the following options:
const options = {
withCredentials: true,
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
};
In my Node-Express server I'm returning the response like this:
return res.redirect('https://google.com');
The browser receives the response with the Location header and attempts to send an OPTIONS request to https://google.com, but this fails because of Google's CORS settings (OPTIONS is not allowed).
I know I could redirect the browser in my client-side JS by using e.g. window.location.replace(), but is it possible to make the browser go to https://google.com (without making an OPTIONS call) just because my backend is telling it to do so?
EDIT: Here's a simplified route:
router.post('/cats', (req, res) => {
if (redirectCondition) {
return res.redirect('https://google.com');
}
return res.sendStatus(200);
});