我有以下注册路由,在成功注册验证消息之后,应该发送该消息,该消息当前不会运行。
示例:mailer.sendEmail(res, req.body, token)
。
控制台中没有错误。我传递参数的方式可能有问题。
有人可以帮忙吗?
server.js
app.post('/signup-user', upload.single('avatar'), (req, res) => {
let sSignupUserImagePath = req.file.path.split("public/").pop()
Object.defineProperty(global, "sSignupUserImagePath", {
value: sSignupUserImagePath
})
let token = jwt.sign({
username: req.body.email,
}, 'supersecret', {
expiresIn: 240
});
user.signupUser(req.body, (err) => {
if (!err) {
mailer.sendEmail(res, req.body, token)
}
})
})
user.js的
var user = {}
user.signupUser = (jUserData, res) => {
var aData = [
null,
jUserData.first_name,
jUserData.last_name,
jUserData.email,
jUserData.mobile_number,
sSignupUserImagePath,
0
]
var sQuery = 'INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?)'
db.run(sQuery, aData, (err) => {
if (err) {
console.log('BAD, user not registered')
return res(err)
}
console.log('GREAT, user registered')
});
}
答案 0 :(得分:0)
执行它们时,您没有调用传递给函数的res函数;如果一切顺利,你必须致电:
db.run(sQuery, aData, (err) => {
if (err) {
console.log('BAD, user not registered')
return res(err)
}
console.log('GREAT, user registered');
res(null); //or also res(); works
});