Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at new NodeError (node:internal/errors:372:5)
在poseman发起post请求,输入任何username,password,返回结果都是成功状态。没有执行sql语句,后台爆出Cannot set headers after they are sent to the client错误
//登陆的处理函数
exports.login = (req, res) => {
//接受表单数据
const userinfo = req.body
//定义sql语句
const sql = select * from ev_users where username=?
//执行sql语句,根据用户名查询用户信息
db.query(sql, userinfo.username, function(err, results) {
// 执行 SQL 语句失败
if (err) return res.cc(err)
// 执行 SQL 语句成功,但是查询到数据条数不等于 1
if (results.length !== 1) return res.cc('登录失败!')
// TODO:判断用户输入的登录密码是否和数据库中的密码一致
})
res.send('login is ok')
}