Files
web/server/src/index.ts
T
xuyueandClaude Opus 5.5 26827e31d5
Deploy / deploy (build, debian, 22) (push) Canceled after 0s
feat: 登录改用 JWT(access token + refresh token),不再用 cookie
- 登录返回 15 分钟的 access token(HS256,密钥 JWT_SECRET,未配置则每次启动随机)
  和 14 天的 refresh token;请求带 Authorization: Bearer,WebSocket 用 ?token=
- refresh token 只存 sha256,放在新表 auth_refresh_token(删除旧的 auth_session);
  POST /account/refresh 换新的 access token,退出、改密码、封号时作废
- 带了无效或过期的 token 一律 401,前端据此刷新:快过期时提前刷新、并发请求只刷新一次,
  401 时刷新后重试一次,refresh token 也失效才退出登录
- 不再用 cookie,去掉 CORS credentials 和写请求的 Origin 校验

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 19:10:55 +08:00

24 lines
707 B
TypeScript

import { app } from "./app"
import { config } from "./config"
import { db } from "./db"
import { upgrade, websocket, type WsData } from "./ws"
const server = Bun.serve<WsData>({
port: config.port,
// 上传素材 / 图片
maxRequestBodySize: 50 * 1024 * 1024,
// AI 生成走 WebSocket,普通接口不会太久
idleTimeout: 120,
async fetch(req, server) {
const res = await upgrade(req, server)
if (res !== null) return res
return app.fetch(req)
},
websocket,
})
// 长期运行的连接按 SQLite 文档建议定期刷新统计信息
setInterval(() => db.run("PRAGMA optimize"), 60 * 60 * 1000)
console.log(`webpreview server listening on http://localhost:${server.port}`)