Skip to content

Commit 6f8d206

Browse files
fix(core): allow chaining nest app instance methods
1 parent f665a19 commit 6f8d206

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/core/nest-factory.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,24 @@ export class NestFactoryStatic {
250250
private createAdapterProxy<T>(app: NestApplication, adapter: HttpServer): T {
251251
const proxy = new Proxy(app, {
252252
get: (receiver: Record<string, any>, prop: string) => {
253+
const mapToProxy = (result: unknown) => {
254+
return result instanceof Promise
255+
? result.then(mapToProxy)
256+
: result instanceof NestApplication
257+
? proxy
258+
: result;
259+
};
260+
253261
if (!(prop in receiver) && prop in adapter) {
254262
return (...args: unknown[]) => {
255-
this.createExceptionZone(adapter, prop)(...args);
256-
return proxy;
263+
const result = this.createExceptionZone(adapter, prop)(...args);
264+
return mapToProxy(result);
257265
};
258266
}
259267
if (isFunction(receiver[prop])) {
260-
const mapToProxy = (result: unknown) =>
261-
result instanceof NestApplication ? proxy : result;
262-
263268
return (...args: unknown[]) => {
264269
const result = receiver[prop](...args);
265-
return result instanceof Promise
266-
? result.then(mapToProxy)
267-
: mapToProxy(result);
270+
return mapToProxy(result);
268271
};
269272
}
270273
return receiver[prop];

0 commit comments

Comments
 (0)