From 148d6119f3b0bd16f4911e698fb25943ade8397f Mon Sep 17 00:00:00 2001 From: YaneonY Date: Wed, 19 Apr 2023 11:28:48 +0200 Subject: [PATCH 1/5] Added parameters for custom glob patterns and glob options, while also preserving backward compatibility with the serveDotFiles option provided by the plugin. --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3251c89c..44deadb1 100644 --- a/index.js +++ b/index.js @@ -336,14 +336,15 @@ async function fastifyStatic (fastify, opts) { }) } } else { - const globPattern = '**/**' + const globPattern = opts.globPattern !== undefined ? opts.globPattern : '**/**'; + const globOptions = typeof opts.globOptions === 'object' ? { ...{ nodir: true, dot: opts.serveDotFiles }, ...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) { From 311a9e6630346f917876fd362d9d469e75c3c36c Mon Sep 17 00:00:00 2001 From: YaneonY Date: Wed, 19 Apr 2023 11:46:54 +0200 Subject: [PATCH 2/5] Changed documentation. --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 2e67fee7..2f605d27 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 optios 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`. From 19a803c26ed3b6de26215be80852710b8b9c2259 Mon Sep 17 00:00:00 2001 From: YaneonY Date: Wed, 19 Apr 2023 13:29:59 +0200 Subject: [PATCH 3/5] Fix for jobs. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 44deadb1..b577a26e 100644 --- a/index.js +++ b/index.js @@ -336,8 +336,8 @@ async function fastifyStatic (fastify, opts) { }) } } else { - const globPattern = opts.globPattern !== undefined ? opts.globPattern : '**/**'; - const globOptions = typeof opts.globOptions === 'object' ? { ...{ nodir: true, dot: opts.serveDotFiles }, ...opts.globOptions } : { nodir: true, dot: opts.serveDotFiles } + const globPattern = opts.globPattern !== undefined ? opts.globPattern : '**/**' + const globOptions = typeof opts.globOptions === 'object' ? { ...{ nodir: true, dot: opts.serveDotFiles }, ...opts.globOptions } : { nodir: true, dot: opts.serveDotFiles } const indexDirs = new Map() const routes = new Set() From d061dd9444a19dc4b43771fcfef7a36df35a02d1 Mon Sep 17 00:00:00 2001 From: YaneonY Date: Thu, 27 Apr 2023 10:57:00 +0200 Subject: [PATCH 4/5] Update README.md Co-authored-by: Frazer Smith --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f605d27..3598f235 100644 --- a/README.md +++ b/README.md @@ -445,7 +445,7 @@ Glob pattern used to match files. Please read full description here: [Glob Prime Default: `{ nodir: true, dot: opts.serveDotFiles }` -Options passed to glob module. All available optios are described here: [Glob Options](https://github.com/isaacs/node-glob#options) +Options passed to glob module. All available options are described here: [Glob Options](https://github.com/isaacs/node-glob#options) #### Disable serving From b58d7923f58361da75930f3a1c288347cabed4ab Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Sun, 14 May 2023 23:03:25 +0200 Subject: [PATCH 5/5] simpler solution --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b577a26e..3493853b 100644 --- a/index.js +++ b/index.js @@ -336,8 +336,8 @@ async function fastifyStatic (fastify, opts) { }) } } else { - const globPattern = opts.globPattern !== undefined ? opts.globPattern : '**/**' - const globOptions = typeof opts.globOptions === 'object' ? { ...{ nodir: true, dot: opts.serveDotFiles }, ...opts.globOptions } : { nodir: true, dot: opts.serveDotFiles } + const globPattern = opts.globPattern || '**/**' + const globOptions = opts.globOptions || { nodir: true, dot: opts.serveDotFiles } const indexDirs = new Map() const routes = new Set()