| 20 | }; |
| 21 | |
| 22 | export class HapiAdapter implements IServerAdapter { |
| 23 | private basePath = ''; |
| 24 | private bullBoardQueues: BullBoardQueues | undefined; |
| 25 | private errorHandler: ((error: Error) => ControllerHandlerReturnType) | undefined; |
| 26 | private statics: { path: string; route: string } | undefined; |
| 27 | private viewPath: string | undefined; |
| 28 | private entryRoute: AppViewRoute | undefined; |
| 29 | private apiRoutes: HapiRouteDef[] | undefined; |
| 30 | private uiConfig: UIConfig = {}; |
| 31 | |
| 32 | public setBasePath(path: string): HapiAdapter { |
| 33 | this.basePath = path; |
| 34 | return this; |
| 35 | } |
| 36 | |
| 37 | public setStaticPath(staticsRoute: string, staticsPath: string): HapiAdapter { |
| 38 | this.statics = { route: staticsRoute, path: staticsPath }; |
| 39 | |
| 40 | return this; |
| 41 | } |
| 42 | |
| 43 | public setViewsPath(viewPath: string): HapiAdapter { |
| 44 | this.viewPath = viewPath; |
| 45 | return this; |
| 46 | } |
| 47 | |
| 48 | public setErrorHandler(handler: (error: Error) => ControllerHandlerReturnType) { |
| 49 | this.errorHandler = handler; |
| 50 | return this; |
| 51 | } |
| 52 | |
| 53 | public setApiRoutes(routes: AppControllerRoute[]): HapiAdapter { |
| 54 | this.apiRoutes = routes.reduce((result, routeRaw) => { |
| 55 | const routes = Array.isArray(routeRaw.route) ? routeRaw.route : [routeRaw.route]; |
| 56 | const methods = Array.isArray(routeRaw.method) ? routeRaw.method : [routeRaw.method]; |
| 57 | |
| 58 | routes.forEach((path) => { |
| 59 | result.push({ |
| 60 | method: methods.map((method) => method.toUpperCase()) as any, |
| 61 | path: toHapiPath(path), |
| 62 | handler: routeRaw.handler, |
| 63 | }); |
| 64 | }); |
| 65 | |
| 66 | return result; |
| 67 | }, [] as HapiRouteDef[]); |
| 68 | |
| 69 | return this; |
| 70 | } |
| 71 | |
| 72 | public setEntryRoute(routeDef: AppViewRoute): HapiAdapter { |
| 73 | this.entryRoute = routeDef; |
| 74 | |
| 75 | return this; |
| 76 | } |
| 77 | |
| 78 | public setQueues(bullBoardQueues: BullBoardQueues): HapiAdapter { |
| 79 | this.bullBoardQueues = bullBoardQueues; |
nothing calls this directly
no outgoing calls
no test coverage detected