Skip to content

Commit

Permalink
fix(nano-server): route generic
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Dec 21, 2022
1 parent e4d3e65 commit 94e181b
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions core/nano-server/src/nano-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class AlwatrNanoServer {
* };
* ```
*/
route<TMeta = Record<string, unknown>, TData = Record<string, unknown>>(
route<TData = Record<string, unknown>, TMeta = Record<string, unknown>>(
method: 'ALL' | Methods,
route: 'all' | `/${string}`,
middleware: (
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -384,16 +380,16 @@ 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',
meta: {
method: connection.method,
route: connection.url.pathname,
},
});
};
};
}

Expand Down

0 comments on commit 94e181b

Please sign in to comment.