From e96575fa47b04c715da7cf7b0c956732652552df Mon Sep 17 00:00:00 2001 From: gegehprast Date: Tue, 30 Aug 2022 02:36:04 +0700 Subject: [PATCH] RouteHandler --- src/http/Types.ts | 3 +++ src/http/router.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/http/Types.ts diff --git a/src/http/Types.ts b/src/http/Types.ts new file mode 100644 index 0000000..cc10f48 --- /dev/null +++ b/src/http/Types.ts @@ -0,0 +1,3 @@ +import express from 'express' + +export type RouteHandler = (router: express.Router) => void diff --git a/src/http/router.ts b/src/http/router.ts index abfc484..78ec9f8 100644 --- a/src/http/router.ts +++ b/src/http/router.ts @@ -1,6 +1,7 @@ import fs from 'fs' import path from 'path' import express from 'express' +import { RouteHandler } from './Types' const ROUTER = express.Router() const ROUTE_PATH = './routes' @@ -12,7 +13,7 @@ const routes = async () => { .filter((file) => file.endsWith('.js') || file.endsWith('.ts')) for (const file of files) { - ;(await import(`${ROUTE_PATH}/${file}`)).default(ROUTER) + ;((await import(`${ROUTE_PATH}/${file}`)).default as RouteHandler)(ROUTER) } return ROUTER