fix: 开发环境 h5 代理配置

This commit is contained in:
h_mo 2024-06-14 14:06:15 +08:00
parent f997a9d6c1
commit 8cc0fc91f4
2 changed files with 5 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import pkg from '../../package.json'; import pkg from '../../package.json';
import { isH5 } from '@/utils/platform';
/** /**
* @description: Generate cache key according to version * @description: Generate cache key according to version
@ -69,7 +70,7 @@ export function isUseMock(): boolean {
* @example: * @example:
*/ */
export function getBaseUrl(): string { export function getBaseUrl(): string {
return getEnvValue<string>('VITE_BASE_URL'); return (isH5 && isDevMode()) ? getEnvValue<string>('VITE_PROXY_PREFIX') : getEnvValue<string>('VITE_BASE_URL');
} }
/** /**
@ -78,5 +79,5 @@ export function getBaseUrl(): string {
* @example: * @example:
*/ */
export function getUploadUrl(): string { export function getUploadUrl(): string {
return getEnvValue<string>('VITE_UPLOAD_URL'); return (isH5 && isDevMode()) ? getEnvValue<string>('VITE_UPLOAD_PROXY_PREFIX') : getEnvValue<string>('VITE_UPLOAD_URL');
} }

View File

@ -70,12 +70,12 @@ export default defineConfig(async ({ mode }) => {
[VITE_PROXY_PREFIX!]: { [VITE_PROXY_PREFIX!]: {
target: VITE_BASE_URL, target: VITE_BASE_URL,
changeOrigin: true, changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/api/, ''), rewrite: (path: string) => path.replace(new RegExp(`^${VITE_PROXY_PREFIX}`), ''),
}, },
[VITE_UPLOAD_PROXY_PREFIX!]: { [VITE_UPLOAD_PROXY_PREFIX!]: {
target: VITE_UPLOAD_URL, target: VITE_UPLOAD_URL,
changeOrigin: true, changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/upload/, ''), rewrite: (path: string) => path.replace(new RegExp(`^${VITE_UPLOAD_PROXY_PREFIX}`), ''),
}, },
}, },
}, },