李富豪 1 year ago
parent
commit
9da42c9464
3 changed files with 13 additions and 6 deletions
  1. 1 1
      Web/src/api/http/config.ts
  2. 1 4
      Web/src/api/http/request.ts
  3. 11 1
      Web/vite.config.ts

+ 1 - 1
Web/src/api/http/config.ts

@@ -4,7 +4,7 @@ export const CURRENT_CONFIG = {
   appKey: '7c9e9108f2ddcbab32d2b508f452151',
   appLicense: 'ZK7Dzih4Qc9JCZhDiyDsWJwTW+1rhnnzT1SqDxbdSPVV24bbDC4r1KNjXo7tIPBnPne7ipnXeefP0lJ0OHvxMpkKiag5lFCIndKSvYYdQkyScT3dahCXjmYsd0YyWyHj4tvXoR2DRVq1PdBHLB1iUo2FGLCIZ8QHbGyqglyGdHY=',
   // 网络请求
-  baseURL: 'http://192.168.3.42:6789/', // This url must end with "/". Example: 'http://192.168.1.1:6789/'
+  baseURL: '/api', 
   websocketURL: 'ws://192.168.3.42:6789/api/v1/ws', // Example: 'ws://192.168.1.1:6789/api/v1/ws'
   // livestreaming
   // RTMP  Note: This IP is the address of the streaming server. If you want to see livestream on web page, you need to convert the RTMP stream to WebRTC stream.

+ 1 - 4
Web/src/api/http/request.ts

@@ -1,5 +1,4 @@
 import axios from 'axios'
-import { uuidv4 } from '/@/utils/uuid'
 import { CURRENT_CONFIG } from './config'
 import { message } from 'ant-design-vue'
 import router from '/@/router'
@@ -7,22 +6,20 @@ import { ELocalStorageKey, ERouterName, EUserType } from '/@/types/enums'
 export * from './type'
 
 const REQUEST_ID = 'X-Request-Id'
+
 function getAuthToken() {
   return localStorage.getItem(ELocalStorageKey.Token)
 }
 
 const instance = axios.create({
-  // withCredentials: true,
   headers: {
     'Content-Type': 'application/json',
   },
-  // timeout: 12000,
 })
 
 instance.interceptors.request.use(
   config => {
     config.headers[ELocalStorageKey.Token] = getAuthToken()
-    // config.headers[REQUEST_ID] = uuidv4()
     config.baseURL = CURRENT_CONFIG.baseURL
     return config
   },

+ 11 - 1
Web/vite.config.ts

@@ -23,7 +23,17 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => defineConfig(
   server: {
     open: true,
     host: '0.0.0.0',
-    port: 8080
+    port: 8080,
+    proxy: {
+      '/api': {
+        // 开启跨域
+        changeOrigin: true,
+        // 转发地址
+        target: 'http://192.168.3.42:6789',
+        // 路径重写
+        rewrite: (path) => path.replace(/^\/api/, ''),
+      }
+    }
   },
   build: {
     target: ['es2015'], // 最低支持 es2015