Prechádzať zdrojové kódy

gis目录提炼到公共资源

zengy 1 hodinu pred
rodič
commit
a0f7942d4b
3 zmenil súbory, kde vykonal 27 pridanie a 1 odobranie
  1. 3 1
      .env.development
  2. 2 0
      .fes.js
  3. 22 0
      src/common/cockpitGisProxyPlugin.js

+ 3 - 1
.env.development

@@ -17,4 +17,6 @@ VITE_COCKPIT_WS_URL='ws://192.168.110.96:8301/ws/deviceStatus'
 VITE_COCKPIT_CONFIG_URL='auto'
 VITE_COCKPIT_BASEMAP_SOURCE='natural-earth'
 
-# GIS 本机路径仍由 .env.local 的 COCKPIT_GIS_MOUNTS 提供,不进入浏览器产物。
+# GIS 公共静态服务地址:dev server 的 /gis 代理目标(Node 侧使用,不进入浏览器产物)。
+# 开发者无需在本地放 GIS 目录;如需离线兜底,才在 .env.local 配 COCKPIT_GIS_MOUNTS 挂本机目录。
+COCKPIT_GIS_ORIGIN='http://192.168.110.30:8099'

+ 2 - 0
.fes.js

@@ -11,6 +11,7 @@ import cesiumStatic from './src/common/cesiumStaticPlugin.js'
 import localGisStatic from './src/common/localGisStaticPlugin.js'
 import cockpitStatic from './src/common/cockpitStaticPlugin.js'
 import cockpitEnvPlugin from './src/common/cockpitEnvPlugin.js'
+import cockpitGisProxy from './src/common/cockpitGisProxyPlugin.js'
 
 export default defineBuildConfig({
     mountElementId: 'tvt-app',
@@ -39,6 +40,7 @@ export default defineBuildConfig({
             localGisStatic(),
             cockpitStatic(),
             cockpitEnvPlugin(),
+            cockpitGisProxy(),
         ],
         build: {
             target: 'esnext',

+ 22 - 0
src/common/cockpitGisProxyPlugin.js

@@ -0,0 +1,22 @@
+import { loadEnv } from 'vite'
+
+/**
+ * 仅在 dev server 生效:把 /gis/... 代理到公共 GIS 静态服务。
+ */
+export default function cockpitGisProxy() {
+    return {
+        name: 'cockpit-gis-proxy',
+        config(config, { mode }) {
+            const env = loadEnv(mode, process.cwd(), '')
+            const target = env.COCKPIT_GIS_ORIGIN
+            if (!target) return {}
+            return {
+                server: {
+                    proxy: {
+                        '/gis': { target, changeOrigin: true },
+                    },
+                },
+            }
+        },
+    }
+}