为API抽象类添加注解和类型限定

This commit is contained in:
2024-09-06 11:58:24 +08:00
parent 2e98682e7e
commit 42cd5015a8

View File

@@ -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);
}