Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wobsoriano/elysia-autoroutes
File system routes for Elysia.js.
https://github.com/wobsoriano/elysia-autoroutes
bun http routing
Last synced: 29 days ago
JSON representation
File system routes for Elysia.js.
- Host: GitHub
- URL: https://github.com/wobsoriano/elysia-autoroutes
- Owner: wobsoriano
- License: mit
- Created: 2023-07-24T06:15:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-28T03:20:45.000Z (12 months ago)
- Last Synced: 2024-11-07T05:24:48.039Z (about 1 month ago)
- Topics: bun, http, routing
- Language: TypeScript
- Homepage:
- Size: 216 KB
- Stars: 113
- Watchers: 3
- Forks: 8
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-elysia - Autoroutes - File system routes. (Plugins)
README
# elysia-autoroutes
File system routes for [Elysia.js](https://elysiajs.com/).
## Install
```bash
bun install elysia-autoroutes
```## Usage
### Register the plugin
Note: It uses your project's `/routes` directory as source by default.
```ts
import { Elysia } from 'elysia'
import { autoroutes } from 'elysia-autoroutes'const app = new Elysia()
.use(
autoroutes({
routesDir: "./routes", // -> optional, defaults to './routes'
prefix: "/api", // -> optional, defaults to ''
generateTags: false, // -> optional, defaults to true
})
)
.listen(3000)export type ElysiaApp = typeof app
```Create your first route
```ts
// routes/index.ts
import type { ElysiaApp } from './app'export default (app: ElysiaApp) => app.get('/', { hello: 'world' })
```### Directory Structure
Files inside your project's `/routes` directory will get matched a url path automatically.
```php
├── app.ts
├── routes
├── index.ts // index routes
├── posts
├── index.ts
└── [id].ts // dynamic params
└── users.ts
└── package.json
```- `/routes/index.ts` → /
- `/routes/posts/index.ts` → /posts
- `/routes/posts/[id].ts` → /posts/:id
- `/routes/users.ts` → /users## License
MIT