From 94e181ba1172399ac992af6dc969c56e4edffbf0 Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Wed, 21 Dec 2022 16:13:54 +0330 Subject: [PATCH] fix(nano-server): route generic --- core/nano-server/src/nano-server.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/core/nano-server/src/nano-server.ts b/core/nano-server/src/nano-server.ts index 0c45cd589..fe212b9db 100644 --- a/core/nano-server/src/nano-server.ts +++ b/core/nano-server/src/nano-server.ts @@ -144,7 +144,7 @@ export class AlwatrNanoServer { * }; * ``` */ - route, TData = Record>( + route, TMeta = Record>( method: 'ALL' | Methods, route: 'all' | `/${string}`, middleware: ( @@ -317,17 +317,13 @@ export class AlwatrNanoServer { this.middlewareList[connection.method]?.[route] || this.middlewareList.ALL[route] || this.middlewareList[connection.method]?.all || - this.middlewareList.ALL.all; + this.middlewareList.ALL.all || + this._notFoundListener; try { - if (typeof middleware === 'function') { - const content = await middleware(connection); - if (content !== null) { - this.reply(serverResponse, content); - } - } - else { - this._notFoundListener(connection); + const content = await middleware(connection); + if (content !== null) { + this.reply(serverResponse, content); } } catch (_err) { @@ -384,8 +380,8 @@ export class AlwatrNanoServer { } } - protected _notFoundListener = (connection: AlwatrConnection): void => { - this.reply(connection.serverResponse, { + protected _notFoundListener = (connection: AlwatrConnection): AlwatrServiceResponseFailed => { + return connection.serverResponse, { ok: false, statusCode: 404, errorCode: 'not_found', @@ -393,7 +389,7 @@ export class AlwatrNanoServer { method: connection.method, route: connection.url.pathname, }, - }); + }; }; }