0

I have NodeJS + Express app and I want to redirect to a POST API from a GET route. I have looked at various posts on SO but none of them seem to be doing what I want to achieve. When I try the code below, I get a 404 error because GET /link2 is not found. Is there a way to redirect to the POST route without using fetch/axios?

app.get('/link1', function(req, res) {
    res.redirect('/link2')
}

app.post('/link2', function(req, res) {
     res.render('index')
}
  • Check this out: https://stackoverflow.com/questions/38810114/node-js-with-express-how-to-redirect-a-post-request – Abhilash Aug 05 '20 at 22:58
  • Also this https://softwareengineering.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect – Abhilash Aug 05 '20 at 22:59
  • 307 status code is the way to go, try that. – Abhilash Aug 05 '20 at 22:59
  • I tried that and I still get the same error which is Cannot GET /link2 Basically I tried res.redirect(307, '/link2') – user00192331231 Aug 05 '20 at 23:04
  • Nah, I tried it didn't work. My understanding is that GET being considered a SAFE and browser-supported method, redirects (between two systems) are always GET. Generally I haven't seen instances of POST for redirect. – Abhilash Aug 05 '20 at 23:30

0 Answers0