chore(mobile): reuse dev-api proxy config for vite preview
This commit is contained in:
@@ -8,19 +8,27 @@ const proxyTarget = process.env.VITE_PROXY_TARGET || 'https://wygj-api.localhost
|
|||||||
// 代理到线上等已带 /dev-api 前缀的网关时,设 VITE_PROXY_KEEP_PREFIX=1 保留前缀
|
// 代理到线上等已带 /dev-api 前缀的网关时,设 VITE_PROXY_KEEP_PREFIX=1 保留前缀
|
||||||
const keepProxyPrefix = process.env.VITE_PROXY_KEEP_PREFIX === '1';
|
const keepProxyPrefix = process.env.VITE_PROXY_KEEP_PREFIX === '1';
|
||||||
|
|
||||||
export default defineConfig({
|
const proxy = {
|
||||||
plugins: [uni()],
|
|
||||||
server: {
|
|
||||||
host: devHost,
|
|
||||||
port: devPort,
|
|
||||||
strictPort: true,
|
|
||||||
proxy: {
|
|
||||||
'/dev-api': {
|
'/dev-api': {
|
||||||
target: proxyTarget,
|
target: proxyTarget,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false,
|
secure: false,
|
||||||
rewrite: (path) => (keepProxyPrefix ? path : path.replace(/^\/dev-api/, ''))
|
rewrite: (path) => (keepProxyPrefix ? path : path.replace(/^\/dev-api/, ''))
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [uni()],
|
||||||
|
server: {
|
||||||
|
host: devHost,
|
||||||
|
port: devPort,
|
||||||
|
strictPort: true,
|
||||||
|
proxy
|
||||||
|
},
|
||||||
|
preview: {
|
||||||
|
host: devHost,
|
||||||
|
port: devPort,
|
||||||
|
strictPort: true,
|
||||||
|
proxy
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user