mirror of
https://gitee.com/h_mo/uniapp-vue3-vite-ts-template
synced 2025-04-05 19:41:44 +08:00
fix: 开发环境 h5 代理配置
This commit is contained in:
parent
f997a9d6c1
commit
8cc0fc91f4
@ -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');
|
||||||
}
|
}
|
||||||
|
@ -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}`), ''),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user