elysia-autoroutes
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i elysia-autoroutes

Weekly Downloads

119

Version

0.5.0

License

MIT

Unpacked Size

14 kB

Total Files

7

Last publish

Collaborators

  • wobsoriano