Closed cekvenich closed 4 years ago
Hi @cekvenich ! So this is just yet another Express middleware. As such, it will only serve requests that make it into the middleware in the first place. This means to prevent this middleware from, say, serving requests where the file as .ts
extension as your example, just set up the routing to not route those into this middleware instance and you're good to go! Here is a simple example:
var staticMiddleware = serveStatic('/path/to/directory')
app.use((req, res, next) => {
if (req.path.endsWith('.ts')) next() // whatever condition you don't want to serve the file
else staticMiddleware(req, res, next)
})
You can make the condition whatever you desire, of course. I hope this helps!
thx. it was obvious after your response.
Hi, lets say I have a file with extension .ts or file mysecret.yaml and I don't want it served. How can I filter/prevent some file extensions and some files from being served?