comments over registerHTTPEndpoint

This commit is contained in:
srgooglo 2022-05-06 08:09:21 +02:00
parent 9b21671be8
commit 70e319665a

View File

@ -174,16 +174,19 @@ class Server {
endpoint.method = FixedMethods[endpoint.method] endpoint.method = FixedMethods[endpoint.method]
} }
// grab the middlewares
let middlewares = [...execs] let middlewares = [...execs]
if (endpoint.middlewares) { if (endpoint.middlewares) {
middlewares = [...middlewares, ...this.resolveMiddlewares(endpoint.middlewares)] middlewares = [...middlewares, ...this.resolveMiddlewares(endpoint.middlewares)]
} }
// make sure method has root object on endpointsMap
if (typeof this.endpointsMap[endpoint.method] !== "object") { if (typeof this.endpointsMap[endpoint.method] !== "object") {
this.endpointsMap[endpoint.method] = {} this.endpointsMap[endpoint.method] = {}
} }
// extend to map
this.endpointsMap[endpoint.method] = { this.endpointsMap[endpoint.method] = {
...this.endpointsMap[endpoint.method], ...this.endpointsMap[endpoint.method],
[endpoint.route]: { [endpoint.route]: {
@ -192,6 +195,7 @@ class Server {
}, },
} }
// set handler
this.httpInterface[endpoint.method](endpoint.route, ...middlewares, this.handleHTTPRequest) this.httpInterface[endpoint.method](endpoint.route, ...middlewares, this.handleHTTPRequest)
} }