| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- /**
- * 本地开发代理(`npm start` / `npm run start:local` 自动启用)
- *
- * ## 为什么需要
- *
- * 线上部署在 `https://ai.fmode.cn/`,接口在 `https://server.fmode.cn/`——
- * **两者同属 fmode.cn 主域**。平台的会话(`r:` SessionToken 之外的部分)依赖同域
- * Cookie 与同域鉴权链路,本地点 `http://localhost:4200` 是跨域,行为与线上不一致,
- * 表现为「线上登录正常、本地登录报错」。
- *
- * 代理把接口挂到 dev server 自身的路径下,浏览器看来就是**同源请求**,
- * 与线上完全一致,业务代码一行不改。
- *
- * ## 路径映射
- *
- * | 本地请求 | 转发到 | 说明 |
- * |-------------------------|-------------------------------------|------|
- * | `/parse/**` | `https://server.fmode.cn/parse/**` | Parse REST(users/me、roles、classes) |
- * | `/api-platform/**` | `https://server.fmode.cn/api/**` | 云函数入口 + `apig/message` + `fmode/mobile`(CORS 兼容层) |
- * | `/api/**` | `https://server.fmode.cn/api/**` | 旧路径,保留兼容;新代码一律走 `/api-platform/**` |
- *
- * 🔴 为什么 app 代码改用 `/api-platform/**`(2026-11-12):
- * `server.fmode.cn` 的 `/api/**` 响应偶尔带两行 `Access-Control-Allow-Origin`
- * (一行回显 origin,一行 `*`),浏览器按「多个值」直接拦掉。
- * 代理把请求挂在 dev server 自己的路径下 → 同源请求 → 浏览器不做 CORS 检查。
- * 生产环境同样要求 nginx 反代 `/api-platform/`,见 `docs/05-operations/平台代理部署.md`。
- *
- * 🔴 只代理这三个前缀,其余请求仍走 SPA 自身路由,避免把前端路由转发出去。
- */
- module.exports = [
- {
- context: ['/parse', '/api-platform'],
- target: 'https://server.fmode.cn',
- changeOrigin: true,
- secure: true,
- pathRewrite: { '^/api-platform': '/api' },
- // 保留 Cookie / Referer 同源语义,与线上一致
- cookieDomainRewrite: 'localhost',
- logLevel: 'warn',
- },
- {
- // 兼容旧路径:存量调用与脚本仍可能直接打 /api/**
- context: ['/api'],
- target: 'https://server.fmode.cn',
- changeOrigin: true,
- secure: true,
- cookieDomainRewrite: 'localhost',
- logLevel: 'warn',
- },
- ];
|