浏览代码

反向代理

yuhan 10 月之前
父节点
当前提交
8b95f324ae
共有 4 个文件被更改,包括 25 次插入7 次删除
  1. 3 1
      .env.development
  2. 2 1
      .env.production
  3. 3 2
      src/utils/request.js
  4. 17 3
      vue.config.js

+ 3 - 1
.env.development

@@ -1,6 +1,8 @@
 NODE_ENV=development
 # VUE_APP_API_BASE_URL=http://192.168.2.244:8520/jeecg-boot
-VUE_APP_API_BASE_URL=http://127.0.0.1:8520/jeecg-boot
+# VUE_APP_API_BASE_URL=http://127.0.0.1:8520/jeecg-boot
+VUE_APP_API_BASE_URL='/dev-api'
+# VUE_APP_API_BASE_URL='/jeecg-boot'
 VUE_APP_CAS_BASE_URL=http://cas.example.org:8443/cas
 VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview
 

+ 2 - 1
.env.production

@@ -1,5 +1,6 @@
 NODE_ENV=production
 # 打包时修改该配置 因为有别的电脑会使用,这里要设置成真实IP
-VUE_APP_API_BASE_URL=http://192.168.31.110:8520/jeecg-boot
+VUE_APP_API_BASE_URL='/interlock'
+# VUE_APP_API_BASE_URL=http://192.168.31.110:8520/jeecg-boot
 VUE_APP_CAS_BASE_URL=http://localhost:8888/cas
 VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview

+ 3 - 2
src/utils/request.js

@@ -11,12 +11,13 @@ import { ACCESS_TOKEN, TENANT_ID } from "@/store/mutation-types"
  * 则映射后端域名,通过 vue.config.js
  * @type {*|string}
  */
-let apiBaseUrl = window._CONFIG['domianURL'] || "/jeecg-boot";
+// 这里不确定隐藏后是否有问题-待研究
+// let apiBaseUrl = window._CONFIG['domianURL'] || "/jeecg-boot";
 //console.log("apiBaseUrl= ",apiBaseUrl)
 // 创建 axios 实例
 const service = axios.create({
   //baseURL: '/jeecg-boot',
-  baseURL: apiBaseUrl, // api base_url
+  baseURL: process.env.VUE_APP_API_BASE_URL + '/jeecg-boot', // api base_url
   timeout: 60000, // 请求超时时间
   withCredentials: true,
 })

+ 17 - 3
vue.config.js

@@ -110,11 +110,25 @@ module.exports = {
       },*/
       /* 注意:jeecgboot前端做了改造,此处不需要配置跨域和后台接口(只需要改.env相关配置文件即可)
           issues/3462 很多人此处做了配置,导致刷新前端404问题,请一定注意*/
-      '/jeecg-boot': {
+      // '/jeecg-boot': {
+      //   target: 'http://127.0.0.1:8520',
+      //   ws: false,
+      //   changeOrigin: true
+      // },
+      [process.env.VUE_APP_API_BASE_URL]: {
         target: 'http://127.0.0.1:8520',
-        ws: false,
-        changeOrigin: true
+        changeOrigin: true,
+        pathRewrite: {
+          ['^' + process.env.VUE_APP_API_BASE_URL]: ''
+        }
       },
+      // '/jeecg-boot': {
+      //   target: 'http://127.0.0.1:8520',
+      //   changeOrigin: true,
+      //   pathRewrite: {
+      //     '^/jeecg-boot': ''
+      //   }
+      // },
     }
   },