diff --git a/libraries/hermes/src/Rest/Rest.ts b/libraries/hermes/src/Rest/Rest.ts index e6ea1c3ba..2d08650ea 100644 --- a/libraries/hermes/src/Rest/Rest.ts +++ b/libraries/hermes/src/Rest/Rest.ts @@ -166,8 +166,7 @@ export class RestController extends ConduitRouter { }; self .checkMiddlewares(context, route.input.middlewares) - .then(r => { - Object.assign(context.context, r); + .then(() => { if (route.input.action !== ConduitRouteActions.GET) { return route.executeRequest(context); } diff --git a/libraries/hermes/src/Router.ts b/libraries/hermes/src/Router.ts index c74abb816..627e23a1a 100644 --- a/libraries/hermes/src/Router.ts +++ b/libraries/hermes/src/Router.ts @@ -80,24 +80,24 @@ export abstract class ConduitRouter { this._middlewareOwners.set(middleware.name, moduleUrl); } - checkMiddlewares(params: ConduitRouteParameters, middlewares?: string[]) { - let primaryPromise = new Promise(resolve => { - resolve({}); - }); + async checkMiddlewares(params: ConduitRouteParameters, middlewares?: string[]) { + let primaryPromise = Promise.resolve(); middlewares?.forEach(m => { const middleware = m.split('?')[0]; if (!this._middlewares?.hasOwnProperty(middleware)) { primaryPromise = Promise.reject('Middleware does not exist'); } else { - primaryPromise = primaryPromise.then(r => { + primaryPromise = primaryPromise.then(() => { return this._middlewares![middleware].executeRequest.bind( this._middlewares![middleware], )(params) .then(p => { if (p.result) { - Object.assign(r as Record, JSON.parse(p.result)); + Object.assign( + params.context as Record, + JSON.parse(p.result), + ); } - return r; }) .catch((err: Error) => { if (!m.includes('?')) throw err;