I'm building a single page admin panel for my website in node express.
I've decided to have one admin view file and to load parts of html into it via jQuery or AJAX or something similar (did not decide yet).
I have to serve these files from static files folder (because i have to load them client side), but problem here is that these files are now avaible for everyone (also .css .js files etc...).
Any possibility how to hide these files from users? Or how to hide certain files or load files on client side which are not public?
And i really dont want to insert all my .css and .js code inside my admin view file.
Found a solution here : How to secure a static route with Express and Nodejs
Sorry for duplicate, i did not find it before.
You should use some kind of authentication like passport and a middleware could be helpful to protect your static files:
app.use('/admin', function(req,res,next){
if(req.user){
return express.static(path.join(__dirname, 'public'));
} else {
res.render(403, 'login', {message:'Please, login!'});
}
});
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