38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import * as plugins from '../plugins.js';
|
|
import { Handler } from './classes.handler.js';
|
|
import { Server } from './classes.server.js';
|
|
|
|
import { type IRoute as IExpressRoute } from 'express';
|
|
|
|
export class Route {
|
|
public routeString: string;
|
|
|
|
/**
|
|
* an object map of handlers
|
|
* Why multiple? Because GET, POST, PUT, DELETE, etc. can all have different handlers
|
|
*/
|
|
public handlerObjectMap = new plugins.lik.ObjectMap<Handler>();
|
|
|
|
public expressMiddlewareObjectMap = new plugins.lik.ObjectMap<any>();
|
|
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);
|
|
}
|
|
}
|