Skip to content

Instantly share code, notes, and snippets.

@framp
Created September 11, 2023 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save framp/a5fca6c2fc1b9b2d6338eab57a0e30ae to your computer and use it in GitHub Desktop.
Save framp/a5fca6c2fc1b9b2d6338eab57a0e30ae to your computer and use it in GitHub Desktop.
import Elysia from "elysia";
const router = new Bun.FileSystemRouter({
style: "nextjs",
dir: import.meta.dir,
});
export const get = () => 'OK';
export default new Elysia()
.all('*', async (context) => {
const relativePath = context.path;
const match = router.match(relativePath);
const method = context.request.method.toLowerCase();
console.log(relativePath);
if (match) {
const route = await import(match.filePath);
return route[method](context);
}
return {
method,
path: context.path,
relativePath,
params: context.params,
match,
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment