typedserver/ts/servertools/classes.route.ts

32 lines
964 B
TypeScript
Raw Normal View History

2023-03-30 13:15:48 +00:00
import * as plugins from '../typedserver.plugins.js';
import { Handler } from './classes.handler.js';
import { Server } from './classes.server.js';
2023-07-01 15:23:49 +00:00
import { type IRoute as IExpressRoute } from 'express';
2023-03-30 13:15:48 +00:00
export class Route {
public routeString: string;
2023-08-03 18:50:18 +00:00
public handlerObjectMap = new plugins.lik.ObjectMap<Handler>();
public expressMiddlewareObjectMap = new plugins.lik.ObjectMap<any>();
2023-03-30 13:15:48 +00:00
public expressRoute: IExpressRoute; // will be set to server route on server start
constructor(ServerArg: Server, routeStringArg: string) {
this.routeString = routeStringArg;
}
/**
* add a handler to do something with requests
* @param handlerArg
*/
public addHandler(handlerArg: Handler) {
this.handlerObjectMap.add(handlerArg);
}
/**
* add a express middleware
* @param middlewareArg
*/
public addExpressMiddleWare(middlewareArg: plugins.express.Application) {
this.expressMiddlewareObjectMap.add(middlewareArg);
}
}