Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

elysia-autoroutes

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia-autoroutes

File system routing for Elysia.

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
108
-23.94%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

bun

FAQs

Package last updated on 28 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts