Created
June 8, 2012 14:46
-
-
Save milani/2895990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = express.createServer(); | |
var publicPath = './public'; | |
var adminPath = './admin'; | |
app.use(express.static( path.resolve( publicPath ) ) ); | |
app.use(function(req,res,next){ | |
// if req.path starts with /admin/ and user is logged in call next | |
// else redirect to login page | |
var userIsLoggedIn = true; // check session etc. | |
if( req.path.indexOf('/admin/') == 0 && userIsLoggedIn ) { | |
next(); | |
} else { | |
// ask user for login | |
} | |
}); | |
app.use('/admin',express.static( path.resolve( adminPath ) ) ); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
...
app.use(express.static( path.resolve( publicPath ) ) );
app.use(function(req, res, next) {
if(req.path.indexOf('/admin') === 0) {
if(req.session && req.session.user) {
next();
} else {
console.log('login failed');
res.redirect('/#login');
}
} else {
//somehow it should skip here the app.use('/admin', express.static('./admin')); line.....
}
});
app.use('/admin',express.static( path.resolve( adminPath ) ) );
...