Node.js with Express: how to redirect a POST request

You can do this:

app.post("https://stackoverflow.com/", function(req, res) {
  res.redirect(307, '/test');
});

Which will preserve the send method.

For reference, the 307 http code spec is:

307 Temporary Redirect (since HTTP/1.1) In this occasion, the request
should be repeated with another URI, but future requests can still use
the original URI.2 In contrast to 303, the request method should not
be changed when reissuing the original request. For instance, a POST
request must be repeated using another POST request.

For more info, see: http://www.alanflavell.org.uk/www/post-redirect.html

Leave a Comment