In Express under Node.js, I’d like to inspect a request under a specific path (say, /restricted) and if it is acceptable, have the request be handled by the static provider, which handles the caching headers etc.
If I simply use app.get('/restricted/:file', ...) and then use res.sendfile to send the static file if approved, it will ignore any caching headers and always send the file.
I can’t use a blanket logged-in check because different users should only get different files.
What is the best way to implement this?
This will use the static middleware when appropriate including all of its functionality. Otherwise you can handle unauthorized requests as appropriate.