chore(mobile): reuse dev-api proxy config for vite preview

This commit is contained in:
2026-07-20 09:18:39 +08:00
parent 95759d7f26
commit 260b7f851e
+16 -8
View File
@@ -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';
const proxy = {
'/dev-api': {
target: proxyTarget,
changeOrigin: true,
secure: false,
rewrite: (path) => (keepProxyPrefix ? path : path.replace(/^\/dev-api/, ''))
}
};
export default defineConfig({ export default defineConfig({
plugins: [uni()], plugins: [uni()],
server: { server: {
host: devHost, host: devHost,
port: devPort, port: devPort,
strictPort: true, strictPort: true,
proxy: { proxy
'/dev-api': { },
target: proxyTarget, preview: {
changeOrigin: true, host: devHost,
secure: false, port: devPort,
rewrite: (path) => (keepProxyPrefix ? path : path.replace(/^\/dev-api/, '')) strictPort: true,
} proxy
}
} }
}); });