scoresaber-reloaded-backend/src/route/route.ts

62 lines
983 B
TypeScript
Raw Normal View History

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