github fastify/fastify-static v11.0.0

37 minutes ago

Breaking changes

dotfiles now defaults to 'ignore' (#620)

Files and directories whose name begins with a dot (.env, .git, .well-known, ...) are no longer served by default: requests for them now return a 404. Previously the default was 'allow'.

This matches the defaults of @fastify/send and serve-static, and protects sensitive files such as .env or .git/config that may be left in the static root. Dotfiles are also excluded from directory listings.

Migration: if you rely on serving dotfiles, for example /.well-known/... for ACME or PGP discovery, opt in explicitly:

fastify.register(require('@fastify/static'), {
  root: path.join(__dirname, 'public'),
  dotfiles: 'allow'
})

If you already set dotfiles explicitly, nothing changes for you.

Features

New list.renderJson option (#630)

Customize the JSON directory listing with a function that receives the same (dirs, files) arguments as list.render. Its return value is sent as application/json.

fastify.register(require('@fastify/static'), {
  root: path.join(__dirname, 'public'),
  list: {
    format: 'json',
    renderJson: (dirs, files) => ({
      dirs: dirs.map(dir => dir.name),
      files: files.map(file => ({ name: file.name, href: file.href }))
    })
  }
})

list.render is unchanged and is still used only for the html format. When list.renderJson is omitted, the JSON response is still controlled by list.jsonFormat.

What's Changed

New Contributors

Full Changelog: v10.1.12...v11.0.0

Don't miss a new fastify-static release

NewReleases is sending notifications on new releases.