2

Basically what will happen is my angular page will make a post request to my express/node js application.

I want express on receiving that post request from angular to redirect to an other URL and also along with redirecting, want to POST data to that web page. How will I use res.redirect("") in node js to also post some data.

Node js Code:

app.post('/ur-book',function(req,res){
    var data=...;
    res.redirect('/abcd');
});

I want to post data on /abcd and redirect to it.

other url will not be in my node app. It will be on a different website.

Mohammed Gadiwala
  • 1,923
  • 2
  • 18
  • 26

1 Answers1

0

Simple way to do this is to create a function that handles request to /abcd and call that function from /ur-book like so

function handleAbcd(req, res) {
    console.log(req.myData); // output will be undefined if it's not comming from /ur-book
    res.json({});
}

app.post('/abcd',handleAbcd);

app.post('/ur-book',function(req,res){

    // if you need to add some data you can add them to req.body or even your own for example req.myData
    req.myData = 'hello';
    handleAbcd(req, res);

});
Molda
  • 5,619
  • 2
  • 23
  • 39