diff --git a/README.md b/README.md index 2e67fee7..3598f235 100644 --- a/README.md +++ b/README.md @@ -435,6 +435,18 @@ Assume this structure with the compressed asset as a sibling of the un-compresse └── index.html ``` +#### `globPattern` + +Default: `'**/**'` + +Glob pattern used to match files. Please read full description here: [Glob Primer](https://github.com/isaacs/node-glob#glob-primer) + +#### `globOptions` + +Default: `{ nodir: true, dot: opts.serveDotFiles }` + +Options passed to glob module. All available options are described here: [Glob Options](https://github.com/isaacs/node-glob#options) + #### Disable serving If you would just like to use the reply decorator and not serve whole directories automatically, you can simply pass the option `{ serve: false }`. This will prevent the plugin from serving everything under `root`. diff --git a/index.js b/index.js index 3251c89c..3493853b 100644 --- a/index.js +++ b/index.js @@ -336,14 +336,15 @@ async function fastifyStatic (fastify, opts) { }) } } else { - const globPattern = '**/**' + const globPattern = opts.globPattern || '**/**' + const globOptions = opts.globOptions || { nodir: true, dot: opts.serveDotFiles } const indexDirs = new Map() const routes = new Set() const winSeparatorRegex = new RegExp(`\\${path.win32.sep}`, 'g') for (const rootPath of Array.isArray(sendOptions.root) ? sendOptions.root : [sendOptions.root]) { - const files = await globPromise(path.join(rootPath, globPattern).replace(winSeparatorRegex, path.posix.sep), { nodir: true, dot: opts.serveDotFiles }) + const files = await globPromise(path.join(rootPath, globPattern).replace(winSeparatorRegex, path.posix.sep), globOptions) const indexes = typeof opts.index === 'undefined' ? ['index.html'] : [].concat(opts.index) for (let file of files) {