Reading postdata received by Bogart router in node.js

ساخت وبلاگ
Hi all!

I am trying to build a site using the https://github.com/nrstott/bogart package in Node.js

There is a HTML form that posts two url-encoded fields:

<input type="input" name="title" />
<textarea name="body"></textarea>

The receiving function is supposed to save the post data to CouchDB. New documents are being created in CouchDB, but none contain the posted field values and that is my problem.

The Bogart API differs to the more common Express API. I am trying to print the POST values to log, but cannot find documentation, and this is far as I have come:

Code:

router.post('posts/', function(req) {
  console.log(req.params); // [object Object]
  console.log(req.body); // [object Object]
  console.log(util.inspect(req.params, false, null); // forEach [Function], join [Function]

  var post = req.params;
  post.type = 'post'; // stores type:"post"
  post.date = new Date(); // stores date:"18/06/2017 20:15:00"
 
  return db.saveDoc(post).then(function(resp){
    return bogard.redirect('./'); // this line is hit and also works
  });
}

Can someone please show me how to extract/log the 'title' and 'body' values?
CodingForums...
ما را در سایت CodingForums دنبال می کنید

برچسب : نویسنده : codingforums بازدید : 194 تاريخ : دوشنبه 29 خرداد 1396 ساعت: 3:33