From 8da9567ca247e769767194f3e5f2b47b53d7df2a Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 3 Oct 2024 13:26:00 +0200 Subject: [PATCH] refactor(api): :rotating_light: Don't export a mutable value --- routes.ts | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/routes.ts b/routes.ts index 0d3bf54e..07700b7c 100644 --- a/routes.ts +++ b/routes.ts @@ -6,18 +6,9 @@ export const routeMatcher = new Bun.FileSystemRouter({ fileExtensions: [".ts", ".js"], }); -// Transform routes to be relative to the api directory -let routes = routeMatcher.routes; - -for (const [route, path] of Object.entries(routes)) { - routes[route] = path.replace(join(process.cwd()), "."); - // If route ends with .test.ts, remove the route (it's a duplicate) - if (route.endsWith(".test")) { - delete routes[route]; - } -} - -// Prevent catch-all routes from being first by reversinbg the order -routes = Object.fromEntries(Object.entries(routes).reverse()); - -export { routes }; +export const routes = Object.fromEntries( + Object.entries(routeMatcher.routes) + .filter(([route]) => !route.endsWith(".test")) + .map(([route, path]) => [route, path.replace(join(process.cwd()), ".")]) + .reverse(), +) as Record;