【发布时间】:2018-07-15 09:07:05
【问题描述】:
我有一个应用,使用 express.static 来访问一些用户信息,路由逻辑是这样的:
app.get('/principal',function(req,res,next){
if(req.query.user=='admin'){
next();
}else{
res.send("not allowed");
}
});
app.use('/principal',express.static('/_site'));
但现在我需要它给所有用户,所以应该是这样的:
var username = '';
app.get('/principal',function(req,res,next){
if(req.query.user){
username = req.query.user;
next();
}else{
res.send("not allowed");
}
});
app.use('/principal',express.static(username+'/_site'));
我的每个用户名都有一个文件夹,我的 express.static() 一直读取用户名 var 为空。
【问题讨论】: