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