serveStatic `exclude` regex

Can I use glob or regex in serveStatic exclude option ?

router.get('/scripts/:file', ({ serveStatic }) => {
  serveStatic('path/to/scripts', {
    permanent: true, // ensure that files are permanently accessible, even after a new version of the site has been deployed.
    exclude: ['some-non-versioned-file.js'], // you can exclude specific files from being served permanently.  You should do this for any files that do not have a hash of the content in the name.
  })
})

Hey Artur. For now it’s just an array of strings. You could glob yourself and output to array at build time. We could also allow use of regex.

1 Like

Thanks for the quick answer @ierceg. Regex would be useful here.

1 Like

@ierceg looks like I’m blocked with permanent feature because of this. We have a lot of static files which we want to serve with XDN router. There is no way to make a dir list using node readDir because it gets bundled in a router and tries to read fs on lambda. We need an option with list of directories which will be scanned and excluded.

Could you just make separate routes for each directory? How many directories are there? What kinds of assets are these? In practice versioned assets all tend to be in a small handful of directories.

You could even use the regex capabilities of the router to make a route for only those directories that contain versioned assets.

1 Like

Thanks, Mark. We did separate routes for permanent and other assets. This helped for now.