我收到错误"Request〈{},any,any,ParsedQs,Record〈string,any〉〉“类型中不存在属性”admin“。此外,nodejs应用程序将不会运行,因为它失败并出现相同的错误。我使用的是typescript x1c 0d1x
app.get('/users', auth, (req, res) => {
console.log(` User is admin = ${req.admin}`);
console.log('Users Page');
res.send('Users Page');
});
function auth(req, res, next) {
if (req.query.admin === 'true') {
req.admin = true;
next();
} else {
res.send('No auth');
}
}
1条答案
按热度按时间nuypyhwy1#
还要确保正确构建URL,例如
http://localhost:3000/users?admin=true