我正在使用 express + node.js 并且我有一个 req 对象,浏览器中的请求是/account 但是当我登录 req.path 时,我得到 '/' --- 而不是 '/account'。
//auth required or redirect
app.use('/account', function(req, res, next) {
console.log(req.path);
if ( !req.session.user ) {
res.redirect('/login?ref='+req.path);
} else {
next();
}
});
req.path 是/什么时候应该是/account ??
最佳答案
自己玩了一会之后,你应该使用:
console.log(req.originalUrl)
关于javascript - 如何使用 express req 对象获取请求路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12525928/