compatibility_date >= 2025-04-01 隐式开启 assets_navigation_prefers_asset_serving: 浏览器【导航请求】不进入 Worker,直接由 SPA 资源层返回 index.html。 /api/oauth/cloudflare/callback 是浏览器跨站重定向的落点(导航请求),于是被截胡 —— 前端在无匹配路由的路径上 hydrate,渲染 React Router 的 404 页面;后端 state 完全没被消费, 表现为「Cloudflare 授权成功,回调却毫无反应」。 用 run_worker_first 路径数组(而非 true),静态资源仍走 asset-first 快路径。 - 新增 tests/deploy_config.test.ts 锁住这条部署配置(此类问题只在生产出现) - 线上复验:导航请求打回调现在返回 Worker 的 400,不再是 200 index.html;/accounts 仍返回 SPA
54 lines
2.2 KiB
JSON
54 lines
2.2 KiB
JSON
// WmailHub Console —— Cloudflare Workers 部署配置(生产)
|
|
// 本地开发不需要 wrangler:直接 `bun run dev`。首次部署前:
|
|
// 1. `bunx wrangler d1 create wmailhub` -> 填 database_id(已完成)
|
|
// 2. `bunx wrangler r2 bucket create wmailhub` (已完成)
|
|
// 3. `bunx wrangler d1 execute wmailhub --remote --file=./migrations/0001_init.sql` 起逐个执行 0001~0004
|
|
// 4. `bunx wrangler secret put SESSION_SECRET` (>=32 位随机串)
|
|
// 5. 配置 CF_OAUTH_CLIENT_ID/SECRET/REDIRECT_URI vars(真实 OAuth 硬前提,缺失时接入接口返回 503)
|
|
{
|
|
"$schema": "../node_modules/wrangler/config-schema.json",
|
|
"name": "wmailhub-console",
|
|
"main": "src/worker.ts",
|
|
"compatibility_date": "2026-09-01",
|
|
"assets": {
|
|
"directory": "./public",
|
|
"binding": "ASSETS",
|
|
"not_found_handling": "single-page-application",
|
|
// 必须显式让 /api/* 先走 Worker:compatibility_date >= 2025-04-01 会隐式开启
|
|
// assets_navigation_prefers_asset_serving,浏览器【导航请求】不进 Worker 而直接拿 index.html。
|
|
// 那样 /api/oauth/cloudflare/callback 这个浏览器重定向落点会被 SPA 资源层截胡,
|
|
// 前端在没有匹配路由的路径上 hydrate,渲染成 React Router 的 404 页面 ——
|
|
// 表现为「Cloudflare 授权明明成功,回调却毫无反应」,后端 state 都没被消费。
|
|
// 用数组(而不是 true)可让静态资源保持 asset-first 快路径,不为每个资源文件多付一次 Worker 调用。
|
|
"run_worker_first": ["/api/*", "/internal/*"]
|
|
},
|
|
"routes": [
|
|
// 自定义域名:wmailhub.adx9.com(CF 自动创建 DNS 记录并签发证书)
|
|
{
|
|
"pattern": "wmailhub.adx9.com",
|
|
"custom_domain": true
|
|
}
|
|
],
|
|
"d1_databases": [
|
|
{
|
|
"binding": "DB",
|
|
"database_name": "wmailhub",
|
|
"database_id": "cfc47e65-c71e-470f-96db-5bc23e3e31a4"
|
|
}
|
|
],
|
|
"r2_buckets": [
|
|
{
|
|
"binding": "R2",
|
|
"bucket_name": "wmailhub"
|
|
}
|
|
],
|
|
"triggers": {
|
|
// TTL 清理每 15 分钟(docs/09 建议);Webhook 重试每 1 分钟
|
|
"crons": ["*/1 * * * *"]
|
|
},
|
|
"vars": {
|
|
// Console 对外地址;OAuth redirect 需在 Cloudflare Dashboard 登记同一域名
|
|
"PUBLIC_BASE_URL": "https://wmailhub.adx9.com"
|
|
}
|
|
}
|