Selaa lähdekoodia

fix: 修正 API_TARGET 地址,确保正确转发请求

xieyong 1 viikko sitten
vanhempi
commit
38c8614a40
1 muutettua tiedostoa jossa 8 lisäystä ja 5 poistoa
  1. 8 5
      vite.config.js

+ 8 - 5
vite.config.js

@@ -1,18 +1,21 @@
-import { defineConfig } from 'vite'
-import uni from '@dcloudio/vite-plugin-uni'
+import { defineConfig } from "vite";
+import uni from "@dcloudio/vite-plugin-uni";
 
 // H5 dev: 通过 Vite 代理把 /api 转发到后端,避开浏览器 CORS。
 // 接入新后端时,把 API_TARGET 改成对应环境即可。
-const API_TARGET = 'http://aiot.zoomwin.com.cn:51001'
+const API_TARGET = 'http://aiot.zoomwin.com.cn:51001/api'
+// const API_TARGET = "http://192.168.1.147:18086";
+// const API_TARGET = "http://192.168.1.102:18086";
 
 export default defineConfig({
   plugins: [uni()],
   server: {
     proxy: {
-      '/api': {
+      "/api": {
         target: API_TARGET,
         changeOrigin: true,
+        rewrite: (path) => path.replace(/^\/api/, ''),
       },
     },
   },
-})
+});