elysia
- elysiajs/elysia
- 参考
- bogeychan/elysia-polyfills
- 可以在 node 环境下使用 elysia
- bogeychan/elysia-polyfills
pnpm add elysia @elysiajs/swagger @elysiajs/static
server.ts
import { Elysia, t } from 'elysia';
import { swagger } from '@elysiajs/swagger';
const app = new Elysia()
.use(swagger())
.post('/sign-in', ({ body }) => signIn(body), {
body: t.Object({
username: t.String(),
password: t.String(),
}),
})
.listen(8080);
export type App = typeof app;
client.ts
import { edenTreaty } from '@elysiajs/eden';
import type { App } from './server';
const app = edenTreaty<App>('http://localhost:8080');
app.signIn
.post({
username: 'saltyaom',
password: 12345678,
})
.then(console.log);
Notes
- 完整流程 https://github.com/elysiajs/elysia/blob/main/src/dynamic-handle.ts
- decorator
- 增加在 context 上
- state
- 增加在 store 上
- context
- request
- set
- store
- body
- query
- params
- headers
- cookies
- handler - 一条路由
- store - 构建时的配置信息
- handle
- hooks
- transform
- beforeHandle
- afterHandle
- validator
- body
- headers
- query
- params
- cookie
- response
- content - ContentType
- application/octet-stream 会让 body 为 arrayBuffer
- 没有则会触发 onParse
- fallback 为基于 header 里的 content-type 进行 parse
- store - 构建时的配置信息