Sails.js发送后不能设置头 [英] Sails.js Can't set headers after they are sent

查看:269
本文介绍了Sails.js发送后不能设置头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用sailsjs v0.10.5。

I am using sailsjs v0.10.5.

我在验证用户电子邮件并重定向之前更新数据库时尝试重定向到登录。

I am trying to redirect to login after verifying user email and update the database before redirect.

我在更新回调中使用重定向。但它更新数据库后发送错误

I am using redirection in my update callback. But it sending the error after updating the database

'Cant send headers after they are sent'. 

以下是我用于重定向的代码:

The following is the code am using for redirection:

verifyEmail: function(req, res){
var userId = req.param('userId');
User.update({id: userId},{isVerified: true}).exec(function(err, user) {
  if (!err) { 
      req.flash('error', 'Your email is verified please login');
      res.redirect('/login'); }else { return res.send(user, 400); }
  });


推荐答案

更新水线功能是异步的,一些res方法以后在可能被触发的范围内?

Update waterline function is asynchronous, are you sure there isnt some res method later in the scope that may be fired before?

这篇关于Sails.js发送后不能设置头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆