Просмотр исходного кода

fix(frontend): H5 部署修复(Mixed Content + global polyfill + h5.router.base)

- config.js: H5 环境 API_BASE_URL 按 window.location.protocol 自动选择
  (https://cfc.iwintrue.com 同源),消除 HTTPS 页面请求 HTTP API 的 Mixed Content 拦截;
  非小程序环境默认值改为 https://cfc.etotem.com.cn(原 http://cfc.iwintrue.com)
- vue.config.js: configureWebpack.node false → { global: true, process: true },
  修复 uni-app H5 运行时 'global is not defined'(模块访问 global.__uniConfig)
- manifest.json: 新增 h5.router.base=/frontend/ 与 devServer.port=8551(H5 部署配置)
- config.test.js: 同步 FALLBACK_HOST 预期为 https://cfc.etotem.com.cn
iwt 1 неделя назад
Родитель
Сommit
52fe45b11d

+ 3 - 1
cfc-frontend/__tests__/config/config.test.js

@@ -15,9 +15,11 @@ beforeEach(() => {
 
 // 与 config.js 保持一致:develop / trial / release 三端统一指向同一生产域名;
 // 非小程序环境、env 缺失或未知 envVersion 时,回落到模块顶部的默认值。
+// 2026-11-03 H5 Mixed Content 修复:默认值改为 https(含 H5 非小程序环境),
+//   H5 页面在浏览器中还会按 window.location.protocol 覆盖为同源 cfc.iwintrue.com。
 // 换域名时只需改这两行(对应 config.js 的 switch 分支与顶部默认值)。
 const PROD_HOST = 'https://cfc.etotem.com.cn'
-const FALLBACK_HOST = 'http://cfc.iwintrue.com'
+const FALLBACK_HOST = 'https://cfc.etotem.com.cn'
 
 describe('config.js', () => {
   beforeEach(() => {

+ 12 - 2
cfc-frontend/config.js

@@ -10,7 +10,7 @@
  * 无需手动修改任何变量,发布到对应环境自动生效。
  */
 
-let API_BASE_URL = 'http://cfc.iwintrue.com'
+let API_BASE_URL = 'https://cfc.etotem.com.cn'
 
 try {
   const accountInfo = uni.getAccountInfoSync()
@@ -32,7 +32,17 @@ try {
     }
   }
 } catch (e) {
-  // 非小程序环境(H5/dev),使用默认地址
+  // 非小程序环境(H5/dev):使用默认地址。
+  // 关键:H5 页面部署在 cfc.iwintrue.com(HTTPS 反代),若 API_BASE_URL 指向 http:// 会触发
+  // Mixed Content 被浏览器拦截;故 H5 下按页面当前协议自动选择(同源,避免跨域+CSP 问题)。
+  try {
+    if (typeof window !== 'undefined' && window.location && window.location.protocol) {
+      const proto = window.location.protocol  // 'https:' | 'http:'
+      API_BASE_URL = proto + '//cfc.iwintrue.com'
+    }
+  } catch (e2) {
+    // 保底:维持模块顶部默认值
+  }
 }
 
 export default {

+ 4 - 0
cfc-frontend/manifest.json

@@ -58,6 +58,10 @@
   "mp-alipay": {},
   "mp-baidu": {},
   "mp-toutiao": {},
+  "h5": {
+    "router": { "base": "/frontend/" },
+    "devServer": { "port": 8551 }
+  },
   "uniStatistics": {
     "enable": false
   },

+ 15 - 1
cfc-frontend/vue.config.js

@@ -1,11 +1,25 @@
 // vue.config.js - disable thread-loader for compatibility
+// 2026-11-03 H5 部署配置:
+//  - publicPath:生产构建产物以 /frontend/ 为根(配合 cfc.iwintrue.com/frontend 反代);
+//    dev 模式保持 '/'(dev server 直接访问 http://127.0.0.1:8551/ 不受影响)
+//  - devServer.port:uni-app H5 dev server 端口 8081 → 8551(原 8080 被 gogs 占用)
 module.exports = {
   parallel: false, // Ensure we use the correct source directory
+  publicPath: process.env.NODE_ENV === 'production' ? '/frontend/' : '/',
   pages: undefined,
+  devServer: {
+    port: 8551
+  },
   configureWebpack: {
     resolve: {
       extensions: ['.vue', '.js', '.json'], // Ensure .vue files resolve correctly
     },
-    node: false,
+    // node:false 会禁用 global/process polyfill,uni-app H5 运行时在浏览器访问 global 报
+    // "global is not defined"(模块 1d50:global.__uniConfig / global["____DA59D6D____"])。
+    // 改用 webpack4 node 配置:注入 global(=> window)与 process,兼容 uni-app H5 运行时。
+    node: {
+      global: true,
+      process: true,
+    },
   },
 }