diff --git a/deno.json b/deno.json index c0102b1..20501cd 100755 --- a/deno.json +++ b/deno.json @@ -1,7 +1,7 @@ { "name": "@bearmetal/router", "description": "A simple router for Deno", - "version": "0.2.3-a", + "version": "0.2.3-b", "stable": true, "files": [ "mod.ts", diff --git a/file_router.ts b/file_router.ts index e20b723..e605e36 100755 --- a/file_router.ts +++ b/file_router.ts @@ -25,7 +25,7 @@ function crawl(dir: string, callback: (path: string) => void) { * ``` */ export class FileRouter extends Router { - constructor(root: string) { + constructor(root: string, _import?: (path: string) => Promise) { super(); crawl(root, async (path) => { let relativePath = path.replace(root, "").replace(/index\/?/, ""); @@ -36,7 +36,9 @@ export class FileRouter extends Router { : `${Deno.cwd()}/${path.replace(/^.?.?\//, "")}`; } relativePath = relativePath.replace(/\.[tj]s/, ""); - const handlers = await import("file://" + path); + const handlers = _import + ? await _import(path) + : await import("file://" + path); if (handlers.default) { handlers.default instanceof Router