Files
ndm-web-client/vite.config.ts
2025-08-29 11:42:53 +08:00

102 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { fileURLToPath, URL } from 'node:url';
import { defineConfig, ProxyOptions } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import vueDevTools from 'vite-plugin-vue-devtools';
const line10ApiProxyList: [string, string][] = [
['/ws', 'ws://10.18.128.10:18103'],
['/minio', 'http://10.18.128.10:9000'],
['/api', 'http://10.18.128.10:18760/api'],
['/1075/api', 'http://10.18.128.10:18760/api'],
['/1001/api', 'http://10.18.129.10:18760/api'],
['/1002/api', 'http://10.18.131.10:18760/api'],
['/1003/api', 'http://10.18.133.10:18760/api'],
['/1004/api', 'http://10.18.135.10:18760/api'],
['/1005/api', 'http://10.18.137.10:18760/api'],
['/1006/api', 'http://10.18.139.10:18760/api'],
['/1007/api', 'http://10.18.141.10:18760/api'],
['/1008/api', 'http://10.18.143.10:18760/api'],
['/1009/api', 'http://10.18.145.10:18760/api'],
['/1010/api', 'http://10.18.147.10:18760/api'],
['/1011/api', 'http://10.18.149.10:18760/api'],
['/1012/api', 'http://10.18.151.10:18760/api'],
['/1013/api', 'http://10.18.153.10:18760/api'],
['/1014/api', 'http://10.18.155.10:18760/api'],
['/1015/api', 'http://10.18.157.10:18760/api'],
['/1016/api', 'http://10.18.159.10:18760/api'],
['/1017/api', 'http://10.18.161.10:18760/api'],
['/1018/api', 'http://10.18.163.10:18760/api'],
['/1019/api', 'http://10.18.165.10:18760/api'],
['/1020/api', 'http://10.18.167.10:18760/api'],
['/1021/api', 'http://10.18.169.10:18760/api'],
['/1022/api', 'http://10.18.171.10:18760/api'],
['/1023/api', 'http://10.18.173.10:18760/api'],
['/1024/api', 'http://10.18.175.10:18760/api'],
['/1025/api', 'http://10.18.177.10:18760/api'],
['/1026/api', 'http://10.18.179.10:18760/api'],
['/1027/api', 'http://10.18.181.10:18760/api'],
['/1028/api', 'http://10.18.183.10:18760/api'],
['/1029/api', 'http://10.18.185.10:18760/api'],
['/1030/api', 'http://10.18.187.10:18760/api'],
['/1031/api', 'http://10.18.189.10:18760/api'],
];
const apiProxyList: [string, string][] = [
// 办公室
// ['/minio', 'http://172.16.6.248:9002'],
// ['/api', 'http://172.16.6.113:18760/api'],
// ['/113/api', 'http://172.16.6.113:18760/api'],
// ['/114/api', 'http://172.16.6.114:18760/api'],
// ...line4ApiProxyList,
...line10ApiProxyList,
];
// https://vite.dev/config/
export default defineConfig((/* { command, mode } */) => {
const viteProxy: Record<string, string | ProxyOptions> = {};
apiProxyList.forEach((apiProxy) => {
const [prefix, target] = apiProxy;
if (prefix === '/ws') {
// from Claude4: 对于WebSocket代理不应该使用rewrite函数。
// WebSocket握手和HTTP请求的处理机制不同rewrite主要是为HTTP请求设计的。
// 会代理到 ws://<IP>:<PORT>/ws
viteProxy[prefix] = {
target,
changeOrigin: true,
ws: true,
rewriteWsOrigin: true,
};
return;
}
viteProxy[prefix] = {
target,
changeOrigin: true,
rewrite: (path) => {
console.log(new Date().toLocaleString());
console.log(`请求路径: ${path}`);
const rewrittenPath = path.replace(new RegExp(`^${prefix}`), '');
console.log(`将代理到: ${target}${rewrittenPath}`);
return rewrittenPath;
},
};
});
return {
plugins: [vue(), vueJsx(), vueDevTools()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
port: 9654,
proxy: viteProxy,
},
};
});