From ab4f8263de2a889c5a7d1662f1e277d837df109f Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 23 Aug 2022 15:13:04 +0700 Subject: [PATCH] feat: ignore option for ServeStaticQuick class --- controllers/middlewares/ServeStaticQuick.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/controllers/middlewares/ServeStaticQuick.js b/controllers/middlewares/ServeStaticQuick.js index c03a1d6..b46557c 100644 --- a/controllers/middlewares/ServeStaticQuick.js +++ b/controllers/middlewares/ServeStaticQuick.js @@ -54,6 +54,11 @@ class ServeStaticQuick { options.etag = true } + if (options.ignore && typeof options.ignore !== 'function') { + // Unlike LiveDirectory, we only support function for simplicity's sake + throw new TypeError('Middleware option ignore must be a function') + } + if (options.lastModified === undefined) { options.lastModified = true } @@ -140,7 +145,10 @@ class ServeStaticQuick { case 'add': case 'addDir': case 'change': - this.files.set(relPath, stat) + // Ensure relative path does not pass ignore function if set + if (!this.#options.ignore || !this.#options.ignore(relPath, stat)) { + this.files.set(relPath, stat) + } break case 'unlink': case 'unlinkDir':