1
+ diff --git a/build.mjs b/build.mjs
2
+ index fe01068d0dd3f788a0978802db1747dd83c5825e..fb099c38cc2cbd59300471e7307625e2fc127f0c 100644
3
+ --- a/build.mjs
4
+ +++ b/build.mjs
5
+ @@ -35,7 +35,7 @@ function viaCache(cache, uri, extns) {
6
+ }
7
+ }
8
+
9
+ - function viaLocal(dir, isEtag, uri, extns) {
10
+ + function viaLocal(dir, isEtag, uri, extns, shouldServe) {
11
+ let i=0, arr=toAssume(uri, extns);
12
+ let abs, stats, name, headers;
13
+ for (; i < arr.length; i++) {
14
+ @@ -43,6 +43,7 @@ function viaLocal(dir, isEtag, uri, extns) {
15
+ if (abs.startsWith(dir) && fs.existsSync(abs)) {
16
+ stats = fs.statSync(abs);
17
+ if (stats.isDirectory()) continue;
18
+ + if (shouldServe && !shouldServe(abs)) continue;
19
+ headers = toHeaders(name, stats, isEtag);
20
+ headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
21
+ return { abs, stats, headers };
22
+ @@ -172,7 +173,7 @@ export default function (dir, opts={}) {
23
+ catch (err) { /* malform uri */ }
24
+ }
25
+
26
+ - let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
27
+ + let data = lookup(pathname, extns, opts.shouldServe) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns, opts.shouldServe);
28
+ if (!data) return next ? next() : isNotFound(req, res);
29
+
30
+ if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
31
+ diff --git a/sirv.d.ts b/sirv.d.ts
32
+ index c05040fc6ec504a1828a7badd39f669981acd0ee..e9597e8b5bf24613a09565f0e13024ae3ca8fa5e 100644
33
+ --- a/sirv.d.ts
34
+ +++ b/sirv.d.ts
35
+ @@ -19,6 +19,8 @@ declare module 'sirv' {
36
+ gzip?: boolean;
37
+ onNoMatch?: (req: IncomingMessage, res: ServerResponse) => void;
38
+ setHeaders?: (res: ServerResponse, pathname: string, stats: Stats) => void;
39
+ + /** patched */
40
+ + shouldServe?: (absoluteFilePath: string) => void;
41
+ }
42
+
43
+ export default function(dir?: string, opts?: Options): RequestHandler;
0 commit comments