proxy.conf.js 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * 本地开发代理(`npm start` / `npm run start:local` 自动启用)
  3. *
  4. * ## 为什么需要
  5. *
  6. * 线上部署在 `https://ai.fmode.cn/`,接口在 `https://server.fmode.cn/`——
  7. * **两者同属 fmode.cn 主域**。平台的会话(`r:` SessionToken 之外的部分)依赖同域
  8. * Cookie 与同域鉴权链路,本地点 `http://localhost:4200` 是跨域,行为与线上不一致,
  9. * 表现为「线上登录正常、本地登录报错」。
  10. *
  11. * 代理把接口挂到 dev server 自身的路径下,浏览器看来就是**同源请求**,
  12. * 与线上完全一致,业务代码一行不改。
  13. *
  14. * ## 路径映射
  15. *
  16. * | 本地请求 | 转发到 | 说明 |
  17. * |-------------------------|-------------------------------------|------|
  18. * | `/parse/**` | `https://server.fmode.cn/parse/**` | Parse REST(users/me、roles、classes) |
  19. * | `/api/**` | `https://server.fmode.cn/api/**` | 云函数入口 + `apig/message` + `fmode/mobile` |
  20. *
  21. * 🔴 只代理这两个前缀,其余请求仍走 SPA 自身路由,避免把前端路由转发出去。
  22. */
  23. module.exports = [
  24. {
  25. context: ['/parse', '/api'],
  26. target: 'https://server.fmode.cn',
  27. changeOrigin: true,
  28. secure: true,
  29. // 保留 Cookie / Referer 同源语义,与线上一致
  30. cookieDomainRewrite: 'localhost',
  31. logLevel: 'warn',
  32. },
  33. ];