2024-04-16 09:13:34 +02:00
|
|
|
import { join } from "node:path";
|
2023-12-08 09:25:31 +01:00
|
|
|
// Returns the route filesystem path when given a URL
|
|
|
|
|
export const routeMatcher = new Bun.FileSystemRouter({
|
2024-04-07 07:30:49 +02:00
|
|
|
style: "nextjs",
|
|
|
|
|
dir: `${process.cwd()}/server/api`,
|
2024-04-16 09:13:34 +02:00
|
|
|
fileExtensions: [".ts", ".js"],
|
2023-12-08 09:25:31 +01:00
|
|
|
});
|
|
|
|
|
|
2024-04-16 09:13:34 +02:00
|
|
|
// Transform routes to be relative to the server/api directory
|
2024-05-06 09:16:33 +02:00
|
|
|
let routes = routeMatcher.routes;
|
2024-04-16 09:13:34 +02:00
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 09:16:33 +02:00
|
|
|
// Prevent catch-all routes from being first by reversinbg the order
|
|
|
|
|
routes = Object.fromEntries(Object.entries(routes).reverse());
|
|
|
|
|
|
2024-04-16 09:13:34 +02:00
|
|
|
export { routes };
|