From 8cc0fc91f41f27912c33dedcb3e444f389c2ce65 Mon Sep 17 00:00:00 2001 From: h_mo <596417202@qq.com> Date: Fri, 14 Jun 2024 14:06:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BC=80=E5=8F=91=E7=8E=AF=E5=A2=83=20h?= =?UTF-8?q?5=20=E4=BB=A3=E7=90=86=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/env.ts | 5 +++-- vite.config.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/env.ts b/src/utils/env.ts index 0910cb1..40f84dd 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -1,4 +1,5 @@ import pkg from '../../package.json'; +import { isH5 } from '@/utils/platform'; /** * @description: Generate cache key according to version @@ -69,7 +70,7 @@ export function isUseMock(): boolean { * @example: */ export function getBaseUrl(): string { - return getEnvValue('VITE_BASE_URL'); + return (isH5 && isDevMode()) ? getEnvValue('VITE_PROXY_PREFIX') : getEnvValue('VITE_BASE_URL'); } /** @@ -78,5 +79,5 @@ export function getBaseUrl(): string { * @example: */ export function getUploadUrl(): string { - return getEnvValue('VITE_UPLOAD_URL'); + return (isH5 && isDevMode()) ? getEnvValue('VITE_UPLOAD_PROXY_PREFIX') : getEnvValue('VITE_UPLOAD_URL'); } diff --git a/vite.config.ts b/vite.config.ts index 2da8c7d..38b9d31 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -70,12 +70,12 @@ export default defineConfig(async ({ mode }) => { [VITE_PROXY_PREFIX!]: { target: VITE_BASE_URL, changeOrigin: true, - rewrite: (path: string) => path.replace(/^\/api/, ''), + rewrite: (path: string) => path.replace(new RegExp(`^${VITE_PROXY_PREFIX}`), ''), }, [VITE_UPLOAD_PROXY_PREFIX!]: { target: VITE_UPLOAD_URL, changeOrigin: true, - rewrite: (path: string) => path.replace(/^\/upload/, ''), + rewrite: (path: string) => path.replace(new RegExp(`^${VITE_UPLOAD_PROXY_PREFIX}`), ''), }, }, },