Skip to content

Commit a7789dc

Browse files
committed
Refactored the merging code
1 parent bbb7b6d commit a7789dc

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

packages/event-handler/src/rest/RouteHandlerRegistry.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,25 +205,22 @@ class RouteHandlerRegistry {
205205
routeHandlerRegistry: RouteHandlerRegistry,
206206
options?: { prefix: Path }
207207
): void {
208-
for (const route of routeHandlerRegistry.#staticRoutes.values()) {
209-
this.register(
210-
new Route(
211-
route.method as HttpMethod,
212-
options?.prefix
213-
? route.path === '/'
214-
? options.prefix
215-
: `${options.prefix}${route.path}`
216-
: route.path,
217-
route.handler,
218-
route.middleware
219-
)
220-
);
221-
}
222-
for (const route of routeHandlerRegistry.#dynamicRoutes) {
208+
const routes = [
209+
...routeHandlerRegistry.#staticRoutes.values(),
210+
...routeHandlerRegistry.#dynamicRoutes,
211+
];
212+
for (const route of routes) {
213+
let path = route.path;
214+
if (options?.prefix) {
215+
path =
216+
route.path === '/'
217+
? options.prefix
218+
: `${options.prefix}${route.path}`;
219+
}
223220
this.register(
224221
new Route(
225222
route.method as HttpMethod,
226-
options?.prefix ? `${options.prefix}${route.path}` : route.path,
223+
path,
227224
route.handler,
228225
route.middleware
229226
)

packages/event-handler/src/rest/Router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,11 @@ class Router {
562562
* const todosRouter = new Router();
563563
*
564564
* todosRouter.get('/todos', async () => {
565-
* // List Todos
565+
* // List API
566566
* });
567567
*
568568
* todosRouter.get('/todos/{todoId}', async () => {
569-
* // Get Todo
569+
* // Get API
570570
* });
571571
*
572572
* const app = new Router();

0 commit comments

Comments
 (0)