Files
dusuniot/src/start.ts
T

22 lines
864 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* # 文件 Start 入口(src/start.ts)
* 注册全局 request middleware:CSRF 保护(server fn RPC)+ 旧链接重定向。
* 该文件由 TanStack Start 插件按约定扫描(默认 entry 名 start)。
*/
import { createStart, createCsrfMiddleware } from "@tanstack/react-start";
import { redirectMiddleware } from "./server/middleware";
import { initDb } from "./db";
// 服务端启动即初始化数据库连接池(惰性 db 的预热;客户端包不含此逻辑)
await initDb();
/** # 成员变量 CSRF 中间件(仅作用于 serverFn RPC 请求) **/
const csrfMiddleware = createCsrfMiddleware({
filter: (ctx) => ctx.handlerType === "serverFn",
});
/** # 成员变量 Start 实例(全局中间件链) **/
export const startInstance = createStart(() => ({
requestMiddleware: [csrfMiddleware, redirectMiddleware],
}));