chore: proxy config
This commit is contained in:
@@ -6,9 +6,10 @@ import vueJsx from '@vitejs/plugin-vue-jsx';
|
|||||||
import vueDevTools from 'vite-plugin-vue-devtools';
|
import vueDevTools from 'vite-plugin-vue-devtools';
|
||||||
|
|
||||||
const line10ApiProxyList: [string, string][] = [
|
const line10ApiProxyList: [string, string][] = [
|
||||||
['/ws', 'ws://10.18.128.10:18103'],
|
|
||||||
['/minio', 'http://10.18.128.10:9000'],
|
['/minio', 'http://10.18.128.10:9000'],
|
||||||
|
|
||||||
['/api', 'http://10.18.128.10:18760/api'],
|
['/api', 'http://10.18.128.10:18760/api'],
|
||||||
|
|
||||||
['/1075/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'],
|
['/1001/api', 'http://10.18.129.10:18760/api'],
|
||||||
@@ -47,39 +48,41 @@ const line10ApiProxyList: [string, string][] = [
|
|||||||
['/1031/api', 'http://10.18.189.10:18760/api'],
|
['/1031/api', 'http://10.18.189.10:18760/api'],
|
||||||
];
|
];
|
||||||
const apiProxyList: [string, string][] = [
|
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,
|
...line10ApiProxyList,
|
||||||
];
|
];
|
||||||
|
const wsProxyList: [string, string][] = [
|
||||||
|
//
|
||||||
|
['/ws', 'ws://10.18.128.10:18103/ws'],
|
||||||
|
];
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig((/* { command, mode } */) => {
|
export default defineConfig((/* { command, mode } */) => {
|
||||||
const viteProxy: Record<string, string | ProxyOptions> = {};
|
const viteProxy: Record<string, string | ProxyOptions> = {};
|
||||||
apiProxyList.forEach((apiProxy) => {
|
apiProxyList.forEach((apiProxy) => {
|
||||||
const [prefix, target] = apiProxy;
|
const [key, target] = apiProxy;
|
||||||
if (prefix === '/ws') {
|
viteProxy[key] = {
|
||||||
// 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,
|
target,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => {
|
rewrite: (path) => {
|
||||||
console.log(new Date().toLocaleString());
|
console.log(new Date().toLocaleString());
|
||||||
console.log(`请求路径: ${path}`);
|
console.log(`请求路径: ${path}`);
|
||||||
const rewrittenPath = path.replace(new RegExp(`^${prefix}`), '');
|
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}`);
|
console.log(`将代理到: ${target}${rewrittenPath}`);
|
||||||
return rewrittenPath;
|
return rewrittenPath;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user