mirror of
https://github.com/makeplane/plane.git
synced 2026-07-14 06:25:58 +02:00
* fix: silo base path improvements * chore: added health check controller --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { RequestHandler, Router } from "express";
|
|
|
|
type HttpMethod = "get" | "post" | "put" | "delete" | "patch" | "options" | "head";
|
|
|
|
export function registerControllers(router: Router, Controller: any) {
|
|
const instance = new Controller();
|
|
const baseRoute = Reflect.getMetadata("baseRoute", Controller) as string;
|
|
|
|
Object.getOwnPropertyNames(Controller.prototype).forEach((methodName) => {
|
|
if (methodName === "constructor") return; // Skip the constructor
|
|
|
|
const method = Reflect.getMetadata("method", instance, methodName) as HttpMethod;
|
|
const route = Reflect.getMetadata("route", instance, methodName) as string;
|
|
const middlewares = (Reflect.getMetadata("middlewares", instance, methodName) as RequestHandler[]) || [];
|
|
|
|
if (method && route) {
|
|
const handler = instance[methodName as keyof typeof instance] as unknown;
|
|
|
|
if (typeof handler === "function") {
|
|
(router[method] as (path: string, ...handlers: RequestHandler[]) => void)(
|
|
`${baseRoute}${route}`,
|
|
...middlewares,
|
|
handler.bind(instance)
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|