mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
refactor(api): 🚨 Don't export a mutable value
This commit is contained in:
parent
076e930369
commit
8da9567ca2
21
routes.ts
21
routes.ts
|
|
@ -6,18 +6,9 @@ export const routeMatcher = new Bun.FileSystemRouter({
|
||||||
fileExtensions: [".ts", ".js"],
|
fileExtensions: [".ts", ".js"],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Transform routes to be relative to the api directory
|
export const routes = Object.fromEntries(
|
||||||
let routes = routeMatcher.routes;
|
Object.entries(routeMatcher.routes)
|
||||||
|
.filter(([route]) => !route.endsWith(".test"))
|
||||||
for (const [route, path] of Object.entries(routes)) {
|
.map(([route, path]) => [route, path.replace(join(process.cwd()), ".")])
|
||||||
routes[route] = path.replace(join(process.cwd()), ".");
|
.reverse(),
|
||||||
// If route ends with .test.ts, remove the route (it's a duplicate)
|
) as Record<string, string>;
|
||||||
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 };
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue