Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daniel-le97/elysia-fs-router
elysia plugin to create a file system router
https://github.com/daniel-le97/elysia-fs-router
Last synced: about 1 month ago
JSON representation
elysia plugin to create a file system router
- Host: GitHub
- URL: https://github.com/daniel-le97/elysia-fs-router
- Owner: daniel-le97
- License: mit
- Created: 2023-08-01T22:00:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-09T02:27:11.000Z (4 months ago)
- Last Synced: 2024-12-09T14:57:49.858Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 57.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elysia-fs-router
## Getting Started
Run `bun install elysia-fs-router`.
## Usage
these can also be found in the examples folder
```js
import Elysia from "elysia";
import { Config, elysiaFsRouter } from "elysia-fs-router";
const config: Config = {
serverDir: '/example/server',
apiPrefix: 'api'
}
const app = new Elysia()
.use(elysiaFsRouter(config))
.listen(3006)
```
```js
// example/server/hello.ts
import { Context } from "elysia";const GET = (ctx: Context) => {
return "Hello," + `${ctx.request.method}`;
}export default {GET}
```
```ts
//example/server/hi.ts
// delete request to http://localhost:3030/api/hi
export function DELETE(ctx: Context){
console.log(ctx.query);
return "hi," + `${ctx.request.method}`;
}
```
```ts
//example/server/posts/[id]-[name].ts
//this will be registered as
/// http://localhost:3030/api/posts/{id}/{name}
import { Context } from "elysia";export default(ctx: Context) => {
return {id: ctx.params?.id, name: ctx.params?.name};
}```
```ts
// example/server/posts/[...all].ts
// http://localhost:3030/api/posts/*
import { Context } from "elysia";export default(ctx: Context) => {
return {params: ctx.params};
}
```## License
MIT