From 52a1cd281794426676dfc4cc92d8f84fca5c181a Mon Sep 17 00:00:00 2001 From: tone <3341154833@qq.com> Date: Fri, 6 Sep 2024 11:58:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BAAPI=E6=8A=BD=E8=B1=A1=E7=B1=BB?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E8=A7=A3=E5=92=8C=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E9=99=90=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/src/Plugs/API/API.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Server/src/Plugs/API/API.ts b/Server/src/Plugs/API/API.ts index 57400bf..29c91b2 100644 --- a/Server/src/Plugs/API/API.ts +++ b/Server/src/Plugs/API/API.ts @@ -1,11 +1,22 @@ +import { Request, Response, NextFunction } from "express"; import Logger from "../Logger"; +interface MiddlewareFunction { + (req: Request, res: Response, next: NextFunction): void; +} + abstract class API { protected logger: Logger; public middlewareFunc: Function[] = []; - constructor(public method: string, public uri: string, ...func: any) { - this.logger = new Logger('API][' + method + '][' + uri); + + /** + * @param method API方法 + * @param path API路由Path + * @param func API中间件函数 + */ + constructor(public method: string, public path: string, ...func: MiddlewareFunction[]) { + this.logger = new Logger('API][' + method + '][' + path); this.middlewareFunc.push(...func); }