diff --git a/cypher-executor/src/index.ts b/cypher-executor/src/index.ts index 6d7a6bb..a61ede1 100644 --- a/cypher-executor/src/index.ts +++ b/cypher-executor/src/index.ts @@ -48,7 +48,28 @@ app.use('*', cors({ extra = String((c.env as Record).UI_ORIGINS || '') .split(',').map((s: string) => s.trim()).filter(Boolean); } catch { /* UI_ORIGINS 未設定=只用靜態白名單 */ } - return [...STATIC_ORIGINS, ...extra].includes(origin) ? origin : null; + + // 🔴 2026-08-08 事故根因修復:**同一台實例的 portal 一律自動放行,不再依賴注入**。 + // + // 那天發生什麼:leo 的 youlin 實例 portal 整個不能用——先是畫面頂端紅字 + // 「設定檔沒載入(config.js)」(UI worker 缺 WORKER_SUBDOMAIN),修好之後**登入仍然失敗**。 + // 瀏覽器 console 實證: + // Access to fetch at '…/portal/login' … blocked by CORS policy: + // No 'Access-Control-Allow-Origin' header is present + // 真因=這台的 `UI_ORIGINS` 沒被設。 + // + // 兩次同一個病:**這些變數只有安裝器那條路會注入,任何人手動 `wrangler deploy` 就會漏掉—— + // 而漏掉時系統看起來完全正常**(worker 上線、HTTP 200、版本號還是對的), + // 只有真人點下去才會發現。leo:「這麼危險的問題已經發生 2 次,不可以再有一次。」 + // + // ⇒ 治法不是「記得要注入」,是**讓它不需要被注入**: + // portal 與本 worker 是同一個 workers.dev 子網域下的兄弟,位址推導得出來。 + // **少一個必須注入的變數,就少一個會被漏掉的東西。** + // `UI_ORIGINS` 仍然有效(自訂網域/額外前端還是靠它),只是不再是「登得進去」的前提。 + const sub = String((c.env as Record).WORKER_SUBDOMAIN || '').trim(); + const sibling = sub ? [`https://arcrun-rag-ui.${sub}.workers.dev`] : []; + + return [...STATIC_ORIGINS, ...sibling, ...extra].includes(origin) ? origin : null; }, allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], allowHeaders: ['Content-Type', 'Authorization', 'X-Arcrun-API-Key'],