28 lines
780 B
TypeScript
28 lines
780 B
TypeScript
import { defineConfig, loadEnv } from 'vite';
|
||
import react from '@vitejs/plugin-react';
|
||
|
||
// 默认走 Go 后端 :4001;要回退 Node 后端就 set VITE_API_TARGET=http://localhost:4000
|
||
export default defineConfig(({ mode }) => {
|
||
const env = loadEnv(mode, process.cwd(), '');
|
||
const target = env.VITE_API_TARGET || 'http://localhost:4001';
|
||
return {
|
||
plugins: [react()],
|
||
server: {
|
||
port: 5173,
|
||
proxy: {
|
||
'/api': {
|
||
target,
|
||
changeOrigin: true,
|
||
// SSE 不要被压缩;保持长连接
|
||
configure: (proxy) => {
|
||
proxy.on('proxyReq', (proxyReq) => {
|
||
proxyReq.setHeader('Accept-Encoding', 'identity');
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
};
|
||
});
|
||
|