Repository navigation
Caline 缺陷修复·服务端:CORS + 响应信封统一(QA #7 缺陷①②) - #19
Merged
todosdev[bot] merged 2 commits intoNov 18, 2026
Merged
Conversation
- implement cors middleware with safe domain validation and preflight 204 - converge admin settings and users endpoints to calineSuccess envelope - unwrap response envelopes in web client request helper - add cors and envelope unwrapping test suites Checkpoint: -GO3I0Sjk21Ojo63wIFPA
…3-79d9-8afb-5567457620fc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
isDomainAllowed+settings.safeDomains)处理 OPTIONS 预检并直接返回 204,为业务响应注入正确的Access-Control-*头。admin.ts:234的双形状 hack 为标准{ data: T }信封;客户端request()统一剥信封并重构错误响应解析,修复后台评论页崩盘及备份导出多包一层data导致的导入失败。Changes
worker/src/middleware/cors.ts:实现 CORS 预检与业务响应头注入中间件,结合readCalineSettings与isDomainAllowed,非法源预检 403,合法源预检 204 并附带完整预检头。worker/src/index.ts:在/api/*前级挂载corsMiddleware,避免预检请求误穿透至鉴权守卫或 404。worker/src/routes/admin.ts:将settings(GET/PUT)、test-email、users(GET 列表及增删改查)统一收敛为calineSuccess信封,彻底移除双形状{ items, data: { items } }兼容 hack。web/src/lib/api.ts:request()自动解包{ data: T },同时兼顾错误信封{ error: { code, message, retryAfter, details } }与老格式的稳健解析。worker/test/cors.test.ts:新增 CORS 专项测试,覆盖公开/受保护端点预检 204、白名单阻断/放行、错误响应跨域保留、同源无 Origin 通行等场景。web/src/lib/api.test.ts:新增响应信封解包、备份导出纯净结构防二次包裹及错误信封解析专项测试。worker/test/admin-*.test.ts等 8 个既有测试用例同步适配信封结构断言。Testing
pnpm typecheck:通过(client、web、worker 零错误)。pnpm lint && pnpm format:check:通过(235 个文件全部合规)。pnpm test:通过(全工程 4 个子包、57 个测试文件、420 项测试全数通过)。pnpm build:打包构建成功(client bundle 与 web SPA 产物均成功编译)。