Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core,common): 馃悰 missing registration handling of SEARCH http verb #13000

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/common/interfaces/http/http-server.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface HttpServer<
all(handler: RequestHandler<TRequest, TResponse>): any;
options(handler: RequestHandler<TRequest, TResponse>): any;
options(path: string, handler: RequestHandler<TRequest, TResponse>): any;
search?(handler: RequestHandler<TRequest, TResponse>): any;
search?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
listen(port: number | string, callback?: () => void): any;
listen(port: number | string, hostname: string, callback?: () => void): any;
reply(response: any, body: any, statusCode?: number): any;
Expand Down
8 changes: 4 additions & 4 deletions packages/core/adapters/http-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export abstract class AbstractHttpAdapter<
return this.instance.all(...args);
}

public search(port: string | number, callback?: () => void);
public search(port: string | number, hostname: string, callback?: () => void);
public search(port: any, hostname?: any, callback?: any) {
return this.instance.search(port, hostname, callback);
public search(handler: RequestHandler);
public search(path: any, handler: RequestHandler);
public search(...args: any[]) {
return this.instance.search(...args);
}

public options(handler: RequestHandler);
Expand Down
37 changes: 17 additions & 20 deletions packages/core/helpers/router-method-factory.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import { HttpServer } from '@nestjs/common';
import { RequestMethod } from '@nestjs/common/enums/request-method.enum';

const REQUEST_METHOD_MAP = {
[RequestMethod.GET]: 'get',
[RequestMethod.POST]: 'post',
[RequestMethod.PUT]: 'put',
[RequestMethod.DELETE]: 'delete',
[RequestMethod.PATCH]: 'patch',
[RequestMethod.ALL]: 'all',
[RequestMethod.OPTIONS]: 'options',
[RequestMethod.HEAD]: 'head',
[RequestMethod.SEARCH]: 'search',
} as const satisfies Record<RequestMethod, keyof HttpServer>;

export class RouterMethodFactory {
public get(target: HttpServer, requestMethod: RequestMethod): Function {
switch (requestMethod) {
case RequestMethod.POST:
return target.post;
case RequestMethod.ALL:
return target.all;
case RequestMethod.DELETE:
return target.delete;
case RequestMethod.PUT:
return target.put;
case RequestMethod.PATCH:
return target.patch;
case RequestMethod.OPTIONS:
return target.options;
case RequestMethod.HEAD:
return target.head;
case RequestMethod.GET:
return target.get;
default: {
return target.use;
}
const methodName = REQUEST_METHOD_MAP[requestMethod];
const method = target[methodName];
if (!method) {
return target.use;
}
return method;
}
}