使用Firebase& amp;表达

时间:2016-03-04 23:34:55

标签: node.js express firebase

我的问题似乎与此问题中的问题完全相同:

Very similar problem on stack

我只是将新博客数据发布到Firebase数据库。数据每次都成功保存到数据库中。按预期工作。但是,当尝试将响应发送回客户端时,我收到此错误:

   Error: Can't set headers after they are sent.
   at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
   at ServerResponse.header 

之前已经在很多问题中讨论过这个主题,但是我无法弄清楚我的代码中的标题写在哪里。这是Firebase的错误吗?

这是我的代码:

router.post('/', function(req, res){
  var rawtitle = req.body.title;
  var author = req.body.author;
  var headline = req.body.headline; 
  var body = req.body.blogtext; 
  var time = Date.now(); 
  var slug = convertToSlug(rawtitle);

  postsDB.push().set({ 
    'title': rawtitle,
    'headline' : headline,
    'slug' : slug,  
    'body': body,
    'created' : time,
    'author' : author
       }, onComplete);

  function onComplete(){
   //following log statement is always false 
   console.log("Have the headers been sent:", res.headersSent); 
   res.send({redirect: '/blog'})
  }

});

非常感谢任何线索

0 个答案:

没有答案