forked from imbytecat/fullstack-starter
refactor(api): 删掉 db ORPC middleware,handler 直接用 db
db middleware 的存在只是为了把 db 注入到 ORPC context——这是 Cloudflare
Workers / 多租户场景的模式(db 依赖 per-request 的 env binding)。在
Bun 单进程 + 模块级 const db 下,这层中间件是纯粹的仪式:一行 import
直接拿到 db,反而更清晰。
- 删除 src/server/api/middlewares/ 整个目录(不留空脚手架,KISS)
- context.ts 去掉 DBContext 与示例注释,只留 BaseContext { headers }
作为未来 auth/tenant 等 middleware 的扩展点
- routers/todo.router.ts 不再 .use(db),handler 内直接 db.query / db.insert
需要 per-request 上下文(auth、tenant、rate-limit)时再按 ORPC 的
os.middleware 模式新增,不在此预先铺陈。
This commit is contained in:
@@ -1,25 +1,3 @@
|
||||
import type { DB } from '@/server/db'
|
||||
|
||||
/**
|
||||
* 基础 Context - 所有请求都包含的上下文
|
||||
*/
|
||||
export interface BaseContext {
|
||||
headers: Headers
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库 Context - 通过 db middleware 扩展
|
||||
*/
|
||||
export interface DBContext extends BaseContext {
|
||||
db: DB
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证 Context - 通过 auth middleware 扩展(未来使用)
|
||||
*
|
||||
* @example
|
||||
* export interface AuthContext extends DBContext {
|
||||
* userId: string
|
||||
* user: User
|
||||
* }
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user