I have an application that uses express.static to access some user information, and the routes logic are like this:
app.get('/principal',function(req,res,next){
if(req.query.user=='admin'){
next();
}else{
res.send("not allowed");
}
});
app.use('/principal',express.static('/_site'));
But now I need it to all users, so should be something like that:
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'));
I have a folder to every username, my express.static() keeps reading the username var empty.
Try to serve static files from the route handler to make it dynamic to the query username:
app.get('/principal',function(req,res,next){
if(req.query.user){
// serve static files for usename
app.use('/principal', express.static(username +'/_site'));
res.send("allowed");
}else{
res.send("not allowed");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With