0.5.0 • Published 5 months ago

elysia-autoroutes v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

elysia-autoroutes

File system routes for Elysia.js.

Install

bun install elysia-autoroutes

Usage

Register the plugin

Note: It uses your project's /routes directory as source by default.

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

// 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.

├── 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

0.5.0

5 months ago

0.3.0

8 months ago

0.4.0

8 months ago

0.2.1

9 months ago

0.2.2

9 months ago

0.2.0

9 months ago

0.1.8

9 months ago

0.1.7

9 months ago

0.1.6

10 months ago

0.1.5

10 months ago

0.1.4

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago