import { NextFunction, Request, Response } from "express"; type Method = "GET" | "POST" | "PUT" | "DELETE" | "ALL"; type RouteType = { /** * The path to handle */ path: string; /** * The method to handle */ method?: Method; }; export abstract class Route { /** * The path to handle */ private path: string; /** * The method to listen for requests on */ private method: Method; constructor({ path, method }: RouteType) { this.path = path; if (!method) { method = "GET"; } this.method = method; } /** * Handle the incoming request * * @param req the request * @param res the response */ abstract handle(req: Request, res: Response, next: NextFunction): void; /** * Get the path of the route * * @returns the path */ getPath() { return this.path; } /** * Get the method of the route * * @returns the method */ getMethod() { return this.method; } }