Categories
express node.js

Restricting access to static files in ExpressJS

I have a server that routes pretty much everything through middleware to check to see if you’re logged in, but that only works for routes. I would also like it to work with static files in the public directory. How would I go about doing that?

update: it’s better to not worry about protecting what’s in the /public folder because express offers a res.download(...) feature. Example on the Express.JS GitHub page