MCPcopy Create free account
hub / github.com/axe-api/axe-api / addHandler

Method addHandler

packages/axe-api/src/Services/URLService.ts:95–151  ·  view source on GitHub ↗
(
    method: string,
    pattern: string,
    customHandler: HandlerFunction,
    middlewares: GeneralFunction[],
  )

Source from the content-addressed store, hash-verified

93 }
94
95 static async addHandler(
96 method: string,
97 pattern: string,
98 customHandler: HandlerFunction,
99 middlewares: GeneralFunction[],
100 ) {
101 LogService.info(`${method} ${pattern}`);
102
103 const phases = middlewares.map((middleware) => {
104 return {
105 isAsync: true,
106 name: middleware.name || `middleware:test`,
107 callback: async (context: IContext) => {
108 if (isMiddlewareFunction(middleware)) {
109 // It should be wrapped
110 const caller = promisify((context: IContext, next: NextFunction) =>
111 (middleware as MiddlewareFunction)(
112 context.req.original,
113 context.res.original,
114 next,
115 ),
116 );
117 await caller(context);
118 } else {
119 // We call it directly.
120 await (middleware as HandlerFunction)(context.req, context.res);
121 }
122 },
123 };
124 });
125
126 const hasTransaction = false;
127
128 phases.push({
129 isAsync: false,
130 name: "customHandler",
131 callback: async (context: IContext) => {
132 customHandler(context.req, context.res);
133 },
134 });
135
136 this.urls.push({
137 method,
138 pattern,
139 phases,
140 hasTransaction,
141 customHandler,
142 data: {
143 version: {} as IVersion,
144 handlerType: HandlerTypes.INSERT,
145 model: {} as IModelService,
146 parentModel: null,
147 relation: null,
148 },
149 parentPairs: [],
150 });
151 }
152

Callers 5

getMethod · 0.80
postMethod · 0.80
putMethod · 0.80
patchMethod · 0.80
deleteMethod · 0.80

Calls 3

isMiddlewareFunctionFunction · 0.90
infoMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected