elysia-file-routing
v1.0.1
Published
File router for Elysia.js.
Downloads
137
Maintainers
Readme
elysia-file-router
File router for Elysia.js inspired by Next.js, Remix, Astro...
Install
bun install elysia-file-routing
Usage
Import and use the plugin fileRouter
in the Elysia app.
By default the value for fileRouter
is "./routes/"
.
// src/index.ts
import { Elysia } from "elysia";
import fileRouter from 'elysia-file-router'
import path from "path";
const app = new Elysia()
.use(fileRouter(path.join(__dirname, 'routes')))
.listen(3000);
A simple GET
route:
// src/routes/get.ts
export default function () {
return {
hello: 'World'
}
}
Using params (path value):
// src/routes/user/[id]/get.ts
export default function ({params: { id }}) {
return {
user_id: id
}
}
The file name specifies the request method
for example a simple POST
endpoint:
// src/routes/user/post.ts
export default function () {
return {
message: "Creating User"
}
}
License
MIT