Skip to content

Commit b7ea184

Browse files
authored
Update BaseMiddleware to allow async handlers (#419)
* feat: update BaseMiddleware to allow async handlers * fix: update Server.resolveMiddleware update resolveMiddleware to return handler result * docs: update docs * feat: update server to return handler result
1 parent 4ae52d1 commit b7ea184

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
### Changed
13+
- Updated `BaseMiddleware.handler` to allow async handlers.
1314

1415
### Fixed
1516

src/base_middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export abstract class BaseMiddleware implements BaseMiddleware {
1818
public abstract handler(
1919
req: Request,
2020
res: Response,
21-
next: NextFunction,
22-
): void;
21+
next: NextFunction
22+
): void | Promise<void>;
2323
}

src/server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,16 @@ export class InversifyExpressServer {
265265
this._container.get<MiddlewareInstance>(middlewareItem);
266266

267267
if (middlewareInstance instanceof BaseMiddleware) {
268-
return (req: Request, res: Response, next: NextFunction): void => {
268+
return (
269+
req: Request,
270+
res: Response,
271+
next: NextFunction,
272+
): void | Promise<void> => {
269273
const mReq: BaseMiddleware =
270274
this._container.get<BaseMiddleware>(middlewareItem);
271275
mReq.httpContext = this._getHttpContext(req);
272-
mReq.handler(req, res, next);
276+
277+
return mReq.handler(req, res, next);
273278
};
274279
}
275280

0 commit comments

Comments
 (0)