Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lullaby6/elysia-file-routing
Bun Package - File router for Elysia.js
https://github.com/lullaby6/elysia-file-routing
bun elysia elysiajs
Last synced: 24 days ago
JSON representation
Bun Package - File router for Elysia.js
- Host: GitHub
- URL: https://github.com/lullaby6/elysia-file-routing
- Owner: lullaby6
- Created: 2024-10-24T21:06:02.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-24T21:41:26.000Z (2 months ago)
- Last Synced: 2024-11-14T15:55:21.880Z (about 2 months ago)
- Topics: bun, elysia, elysiajs
- Language: TypeScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# elysia-file-router
File router for Elysia.js inspired by Next.js, Remix, Astro...
## Install
```bash
bun install elysia-file-routing
```## Usage
Import and use the plugin ```fileRouter``` in the Elysia app.
By default the value for ```fileRouter``` is ```"./routes/"```.
```js
// 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:
```js
// src/routes/get.ts
export default function () {
return {
hello: 'World'
}
}
```Using params (path value):
```js
// 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:
```js
// src/routes/user/post.ts
export default function () {
return {
message: "Creating User"
}
}
```## License
MIT