From ba7525c676e9604f81cdfbfd194a9430f02c9eda Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Fri, 4 May 2018 22:10:14 +0900 Subject: [PATCH] Ignore files and directories with leading dots except .well-known --- src/core/create_routes.ts | 2 +- test/unit/create_routes.test.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/create_routes.ts b/src/core/create_routes.ts index 5ebdad9e1..c3050666c 100644 --- a/src/core/create_routes.ts +++ b/src/core/create_routes.ts @@ -6,7 +6,7 @@ import { Route } from '../interfaces'; export default function create_routes({ files } = { files: glob.sync('**/*.*', { cwd: locations.routes(), dot: true, nodir: true }) }) { const routes: Route[] = files .map((file: string) => { - if (/(^|\/|\\)_/.test(file)) return; + if (/(^|\/|\\)(_|\.(?!well-known))/.test(file)) return; if (/]\[/.test(file)) { throw new Error(`Invalid route ${file} — parameters must be separated`); diff --git a/test/unit/create_routes.test.js b/test/unit/create_routes.test.js index 112e95c6b..8b523506d 100644 --- a/test/unit/create_routes.test.js +++ b/test/unit/create_routes.test.js @@ -150,6 +150,17 @@ describe('create_routes', () => { ); }); + it('ignores files and directories with leading dots except .well-known', () => { + const routes = create_routes({ + files: ['.well-known', '.unknown'] + }); + + assert.deepEqual( + routes.map(r => r.file), + ['.well-known'] + ); + }); + it('matches /foo/:bar before /:baz/qux', () => { const a = create_routes({ files: ['foo/[bar].html', '[baz]/qux.html']