我使用的是express + node.js,我有一个请求对象,浏览器中的请求是/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吗??
发布于 2012-09-21 16:51:04
在我自己做了一些尝试之后,你应该使用:
console.log(req.originalUrl)
发布于 2013-05-19 19:17:34
在某些情况下,您应该使用:
req.path
这将为您提供路径,而不是完整的请求URL。例如,如果您只对用户请求的页面感兴趣,而不是对url的所有参数感兴趣:
/myurl.htm?allkinds&ofparameters=true
req.path将为您提供:
/myurl.html
发布于 2013-04-22 09:38:12
它应该是:
req.url
express 3.1.x
https://stackoverflow.com/questions/12525928
复制相似问题