I am relatively new to web development and I am trying to setup a basic authentication. It works fine for non-static paths, however I am having trouble understanding how static path works. I recently discovered that when I request my authenticated page (/home) using a static path .../home.html, it serves the path no matter what. I already tried to authenticate it the same way I authenticated /home, however it does not work, although I see from console log that authentication fails, so isAuthenticated is called.
I would greatly appreciate if someone can point me to the right direction, as I am trying to understand the difference between asking /home, and /home.html in order to have a proper authentication. I also noticed that most websites I visit online does not have any static paths when I navigate through them. Since only way I know how to redirect a page from button is to use href=/path.html, I also serve static paths after the first button click. It would be good to know how to serve a non-static path (href=/path do not work if I dont add .html at the end)
Probably answer is rather straightforward, but I do not know which words I should look into and to my best knowledge I couldn't find this on stackoverflow as well. So please help me with this noob question.
function isAuthenticated(request, response, next) {
console.log('isauthenticated:'+request.isAuthenticated());
if (request.isAuthenticated()){return next();}
else{response.redirect('/');}
}
app.use('/home', isAuthenticated, function(request, response){
response.render('home.html');
//response.send('if you are viewing this page it means you are logged in');
});
app.use(express.static(__dirname + '/home'), isAuthenticated, function(request, response){
//should serve the page here
});
via OE1
No comments:
Post a Comment