Skip to content

Commit 202b6e4

Browse files
Merge pull request nestjs#3579 from tonyhallett/refactor_core_router-explorer_proxy
refactor(core): remove duplicated code
2 parents ff085c8 + 4c433ee commit 202b6e4

1 file changed

Lines changed: 15 additions & 23 deletions

File tree

packages/core/router/router-explorer.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -184,30 +184,22 @@ export class RouterExplorer {
184184
str[str.length - 1] === '/' ? str.slice(0, str.length - 1) : str;
185185

186186
const isRequestScoped = !instanceWrapper.isDependencyTreeStatic();
187-
const module = this.container.getModuleByKey(moduleKey);
188-
189-
if (isRequestScoped) {
190-
const handler = this.createRequestScopedHandler(
191-
instanceWrapper,
192-
requestMethod,
193-
module,
194-
moduleKey,
195-
methodName,
196-
);
187+
const proxy = isRequestScoped
188+
? this.createRequestScopedHandler(
189+
instanceWrapper,
190+
requestMethod,
191+
this.container.getModuleByKey(moduleKey),
192+
moduleKey,
193+
methodName,
194+
)
195+
: this.createCallbackProxy(
196+
instance,
197+
targetCallback,
198+
methodName,
199+
moduleKey,
200+
requestMethod,
201+
);
197202

198-
paths.forEach(path => {
199-
const fullPath = stripSlash(basePath) + path;
200-
routerMethod(stripSlash(fullPath) || '/', handler);
201-
});
202-
return;
203-
}
204-
const proxy = this.createCallbackProxy(
205-
instance,
206-
targetCallback,
207-
methodName,
208-
moduleKey,
209-
requestMethod,
210-
);
211203
paths.forEach(path => {
212204
const fullPath = stripSlash(basePath) + path;
213205
routerMethod(stripSlash(fullPath) || '/', proxy);

0 commit comments

Comments
 (0)