jiuling hace 4 días
padre
commit
46616d1165
Se han modificado 1 ficheros con 21 adiciones y 1 borrados
  1. 21 1
      vite.config.js

+ 21 - 1
vite.config.js

@@ -2,7 +2,7 @@ import { defineConfig, loadEnv } from 'vite'
 import path from 'path'
 import createVitePlugins from './vite/plugins'
 
-const baseUrl = 'http://localhost:8080' // 后端接口
+const baseUrl = 'http://localhost:8089' // 后端接口
 
 // https://vitejs.dev/config/
 export default defineConfig(({ mode, command }) => {
@@ -25,6 +25,10 @@ export default defineConfig(({ mode, command }) => {
       // https://cn.vitejs.dev/config/#resolve-extensions
       extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
     },
+    define: {
+      // 解决 sockjs-client / stompjs 在浏览器中引用 global 未定义的问题
+      'global': 'globalThis'
+    },
     // 打包配置
     build: {
       // https://vite.dev/config/build-options.html
@@ -51,6 +55,22 @@ export default defineConfig(({ mode, command }) => {
           target: baseUrl,
           changeOrigin: true,
           rewrite: (p) => p.replace(/^\/dev-api/, '')
+        },
+        // 后端API代理 - 处理 /v1/* 请求(如瓦片地图接口)
+        '/v1': {
+          target: baseUrl,
+          changeOrigin: true
+        },
+        // WebSocket/SockJS proxy - 保持 /ws/robot 路径不变,因为后端端点就是 /ws/robot
+        '/ws/robot': {
+          target: baseUrl,
+          changeOrigin: true,
+          ws: true
+        },
+        '/ws': {
+          target: baseUrl,
+          changeOrigin: true,
+          ws: true
         },
          // springdoc proxy
          '^/v3/api-docs/(.*)': {