Created
September 11, 2023 11:21
-
-
Save framp/a5fca6c2fc1b9b2d6338eab57a0e30ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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