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}`), ''), }, }, },