From f5ad1e331368d0bf2082406f623e5b7db65822bd Mon Sep 17 00:00:00 2001 From: dzq Date: Sat, 1 Nov 2025 11:16:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=92=8C=E4=BB=A3=E7=90=86=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改manifest.json中的h5路由基础路径为根路径 更新开发和生产环境的API基础URL为线上地址 调整代理配置并添加错误处理机制 移除未使用的token头设置 --- env/.env | 10 ++++++---- env/.env.development | 3 ++- src/http/interceptor.ts | 4 ++-- src/manifest.json | 2 +- vite.config.ts | 15 ++++++++++++++- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/env/.env b/env/.env index a50de25..12c1e8a 100644 --- a/env/.env +++ b/env/.env @@ -6,18 +6,20 @@ VITE_WX_APPID = 'wxb9ab79f2ddd11af0' # h5部署网站的base,配置到 manifest.config.ts 里的 h5.router.base # https://uniapp.dcloud.net.cn/collocation/manifest.html#h5-router -VITE_APP_PUBLIC_BASE=/h5/ +# VITE_APP_PUBLIC_BASE=/h5/ +VITE_APP_PUBLIC_BASE=/ # 后台请求地址 -VITE_SERVER_BASEURL = 'http://localhost:8090/api/' +# VITE_SERVER_BASEURL = 'http://localhost:8090/api/' +VITE_SERVER_BASEURL = 'http://wxshop.ab98.cn' # 后台上传地址 VITE_UPLOAD_BASEURL = 'http://localhost:8081/upload' # 汇邦云token请求地址 VITE_HUIBANG_BASEURL = 'https://www.ab98.cn' # h5是否需要配置代理 -VITE_APP_PROXY_ENABLE = false -VITE_APP_PROXY_PREFIX = '/api' +VITE_APP_PROXY_ENABLE = true +VITE_APP_PROXY_PREFIX = '/api/' # 第二个请求地址 (目前alova中可以使用) VITE_API_SECONDARY_URL = 'http://wxshop.ab98.cn' diff --git a/env/.env.development b/env/.env.development index 9504787..008822d 100644 --- a/env/.env.development +++ b/env/.env.development @@ -10,4 +10,5 @@ VITE_SHOW_SOURCEMAP = false # 汇邦云token请求地址 #VITE_HUIBANG_BASEURL = 'https://www.ab98.cn' - VITE_SERVER_BASEURL = 'http://localhost:8090/api/' +# VITE_SERVER_BASEURL = 'http://localhost:8090/api/' +VITE_SERVER_BASEURL = 'http://wxshop.ab98.cn' diff --git a/src/http/interceptor.ts b/src/http/interceptor.ts index 1736a1f..35c9c86 100644 --- a/src/http/interceptor.ts +++ b/src/http/interceptor.ts @@ -47,8 +47,8 @@ const httpInterceptor = { ...options.header, } if (getToken()) { - options.header.Authorization = getToken() - options.header['Token'] = getToken(); +/* options.header.Authorization = getToken() + options.header['Token'] = getToken(); */ } }, } diff --git a/src/manifest.json b/src/manifest.json index ee2d7a9..04f4881 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -110,7 +110,7 @@ "vueVersion": "3", "h5": { "router": { - "base": "/h5/" + "base": "/" }, "devServer": {} } diff --git a/vite.config.ts b/vite.config.ts index 22b50f7..7582e5a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -166,7 +166,20 @@ export default ({ command, mode }) => { [VITE_APP_PROXY_PREFIX]: { target: VITE_SERVER_BASEURL, changeOrigin: true, - rewrite: path => path.replace(new RegExp(`^${VITE_APP_PROXY_PREFIX}`), ''), + rewrite: path => path.replace(new RegExp(`^${VITE_APP_PROXY_PREFIX}`), '/shop-api/api/'), + // 添加错误处理和重试机制 + configure: (proxy, options) => { + proxy.on('error', (err, req, res) => { + console.log('代理错误', err); + }); + proxy.on('proxyReq', (proxyReq, req, res) => { + console.log('发送请求到目标服务器', Object.keys(proxyReq)); + console.log('发送请求到目标服务器', req.method, req.host, req.url); + }); + proxy.on('proxyRes', (proxyRes, req, res) => { + console.log('从目标服务器收到响应', proxyRes.statusCode, req.url); + }); + }, }, } : undefined,