我想创建一个获取数据的 API。但是,函数 res.json() 根据下面的消息发现了问题
web_1 | Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
web_1 | at ServerResponse.setHeader (_http_outgoing.js:533:11)
web_1 | at ServerResponse.header (/mbs_welfare/node_modules/express/lib/response.js:771:10)
web_1 | at ServerResponse.send (/mbs_welfare/node_modules/express/lib/response.js:170:12)
web_1 | at /mbs_welfare/server.js:45:9
web_1 | at Layer.handle_error (/mbs_welfare/node_modules/express/lib/router/layer.js:71:5)
web_1 | at trim_prefix (/mbs_welfare/node_modules/express/lib/router/index.js:315:13)
web_1 | at /mbs_welfare/node_modules/express/lib/router/index.js:284:7
web_1 | at Function.process_params (/mbs_welfare/node_modules/express/lib/router/index.js:335:12)
web_1 | at next (/mbs_welfare/node_modules/express/lib/router/index.js:275:10)
web_1 | at Layer.handle_error (/mbs_welfare/node_modules/express/lib/router/layer.js:67:12)
l
router.get('/profile/user/me', async (req, res, next) => {
let user = req.session.user;
if(user) {
try {
let me = user.adminID
let info = await knex('admin_accounts').where('adminID', me)
res.json(info)
} catch (e) {
console.log(e);
}
res.sendFile(path.join(__dirname + '/../public/personal_information.html'));
}else{
res.redirect('/');
}
});
米脂
相关分类