307重定向,无需双邮政快递js

时间:2018-06-21 13:05:29

标签: node.js forms express redirect url-redirection

当用户首先请求action路由时,它将发出POST请求路由idg/webhook路由并重定向到同一路由

const action = function action(req,res){
    //make a POST request 
    requestify.request('http://localhost:3005/idg/webhook', {
        method: 'POST',
        body: {
            foo: 'bar',
            bar: 'foo'
        },
        headers: {
            'Content-type': 'application/json'
        },
        dataType: 'json'
    })
    .then(function(response) {
    });
    //redirect to same url after the post
    res.redirect(308,'http://localhost:3005/idg/webhook');
}

idg/webhook路线

 const webhook = function webhook(req,res){
    console.log("webhook post",req.body);

    res.send('ok');
}

但是问题是action路由也是POST路由,因为我在req.body路由中得到两个idg/webhook

idg/webhook的输出

webhook post { foo: 'bar', bar: 'foo' }
webhook post { submit: 'submit' }

我想删除POST路线的action请求,这怎么可能?

0 个答案:

没有答案