diff --git a/src/router.ts b/src/router.ts index 06e88b7..8263682 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,4 +1,4 @@ -import type { Express } from "express" +import type { Express, Router } from "express" import path from "path" import type { Options } from "./types" @@ -10,6 +10,8 @@ import { getHandlers, getMethodKey } from "./utils" const REQUIRE_MAIN_FILE = path.dirname(require.main?.filename || process.cwd()) +type ExpressLike = Express | Router + /** * Attach routes to an Express app or router instance * @@ -20,7 +22,10 @@ const REQUIRE_MAIN_FILE = path.dirname(require.main?.filename || process.cwd()) * @param app An express app or router instance * @param options An options object (optional) */ -const createRouter = (app: T, options: Options = {}): T => { +const createRouter = ( + app: T, + options: Options = {} +): T => { const files = walkTree( options.directory || path.join(REQUIRE_MAIN_FILE, "routes") ) @@ -45,7 +50,7 @@ const createRouter = (app: T, options: Options = {}): T => { // wildcard default export route matching if (typeof exports.default !== "undefined") { - ;(app as unknown as any).all(url, ...getHandlers(exports.default)) + app.all.apply(null, [url, ...getHandlers(exports.default)]) } }