Files
ndm-web-client/vite.config.ts
2025-11-04 22:12:23 +08:00

105 lines
3.4 KiB
TypeScript

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][] = [
['/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][] = [
//
...line10ApiProxyList,
];
const wsProxyList: [string, string][] = [
//
['/ws', 'ws://10.18.128.10:18103/ws'],
];
// https://vite.dev/config/
export default defineConfig((/* { command, mode } */) => {
const viteProxy: Record<string, string | ProxyOptions> = {};
apiProxyList.forEach((apiProxy) => {
const [key, target] = apiProxy;
viteProxy[key] = {
target,
changeOrigin: true,
rewrite: (path) => {
console.log(new Date().toLocaleString());
console.log(`请求路径: ${path}`);
const rewrittenPath = path.replace(new RegExp(`^${key}`), '');
console.log(`将代理到: ${target}${rewrittenPath}`);
return rewrittenPath;
},
};
});
wsProxyList.forEach((wsProxy) => {
const [key, target] = wsProxy;
viteProxy[key] = {
target,
changeOrigin: true,
ws: true,
rewrite: (path) => {
console.log(new Date().toLocaleString());
console.log(`请求路径: ${path}`);
const rewrittenPath = path.replace(new RegExp(`^${key}`), '');
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,
},
};
});