I have a middle-layer that works as a copuling between a frontend and an api-service. For all posts, I simply want to forward them to the api-service.
For example when I post this form:
<form method="post" action="../rest/1/comment/create" class="questionResponseForm expandable">
<textarea name="content" class="questionResponseTextarea"></textarea>
<input type="hidden" name="code" value="1-1454406440-58e7fa2e7897ffb90c9391febdd9c49c2bd2f3d6">
<input type="hidden" name="q_id" value="1425">
<input type="hidden" name="p_id" value="1425">
<button type="submit" class="questionResponseButton trigger"><svg class="questionTitleIcon"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-pencil"></use></svg>Kommentera frågan</button>
</form>
I want to post the exact same form but to another server.
I use requstify for this:
app.apiUrl in my case is localhost (the node server runs on localhost:3000) req.originalUrl makes sure the same url is used. req.body contains the post-parameters.
app.post('/rest/1/:object/:method', post);
function post(req,res){
var fullUrl = app.apiUrl + req.originalUrl,
requestify = require('requestify');
requestify.post(fullUrl, req.body).then(function(response) {
console.log(response);
app.res.render('master',response);
})
}
req.body:
{ content: 'öljkökljölkjölkj',
code: '1-1454409967-dd95a558b2753d8f2f6239c1a2614b32d51474d0',
q_id: '1422',
p_id: '1422' }
"then" never seems to be triggered, making me suspect there is something wrong with the post.