Answer the question
In order to leave comments, you need to log in
How to give html page only to authorized users in express?
Hello. I am writing a chat on express and passport. Understood with authorization. Works like this:
function authUser() {
return function(request, response, next) {
request.isAuthenticated() ? next() : response.redirect('/')
}
}
app.get('/chat', authUser(), (req, res) => {
res.send('Это видят только авторизованные пользователи')
})
app.get('/chat', authUser(), (req, res) => {
response.sendFile(path.join(`${__dirname}/static/html/chat.html`))
})
Answer the question
In order to leave comments, you need to log in
Yes, everything is fine, you can use a template engine if you need replacements later, or even just cache it to a file so that you don’t read it from the hard disk every time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question