0

i have a function which under some conditions redirects using

return res.redirect('/logout');

i handle the above redirect using

app.route('/logout').post(users.signout);

but the problem is that res.redirect is using a get call and not a post call. enter image description here

I do know i can just handle it as a get call but is there anyway to make it so that res.redirect raises a post call?

uday
  • 9
  • 6
  • 1
    Does this answer your question? [Node.js with Express: how to redirect a POST request](https://stackoverflow.com/questions/38810114/node-js-with-express-how-to-redirect-a-post-request) – ziishaned Aug 26 '21 at 10:45
  • yes for the most part. in the answer you mentioned they used app.post('/test', function(req, res) { res.send('/test page'); }); in my case i don't have an app reference, i am just raising a res.redirect(/logout) do you happen to know how to do the same in my case? – uday Aug 26 '21 at 11:10

1 Answers1

0

I am not sure whether you can call POST method from redirect but there is something else you can do.

app.route('/logout/SpecificRoute').get(users.signout) {
    //Here you can write the code you wanted to execute in the POST method and if  
    //you want some data, you can use route params.
};
app.route('/logout').get(users.signout);

But make sure to call app.route('/logout/SpecificRoute').get(users.signout)before app.route('/logout/:DataParams').get(users.signout) if you are using routes with params as well.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Someone
  • 9
  • 1
  • 7