Browse Source

改成反向代理方式连后端

dongjh 6 months ago
parent
commit
ba49970abc
5 changed files with 16 additions and 6 deletions
  1. 3 1
      .env.development
  2. 3 1
      .env.production
  3. 3 1
      src/config/index.js
  4. 1 1
      src/utils/request.js
  5. 6 2
      vue.config.js

+ 3 - 1
.env.development

@@ -1,5 +1,7 @@
 NODE_ENV=development
-VUE_APP_API_BASE_URL=http://localhost:8867/jeecg-boot
+# VUE_APP_API_BASE_URL=http://localhost:8867/jeecg-boot
+# // 部署修改
+VUE_APP_API_BASE_URL='/dev-api'
 VUE_APP_CAS_BASE_URL=http://cas.example.org:8443/cas
 VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview
 

+ 3 - 1
.env.production

@@ -1,4 +1,6 @@
 NODE_ENV=production
-VUE_APP_API_BASE_URL=http://localhost:8867/jeecg-boot
+# 打包时修改该配置 根据nginx中反向代理设置进行修改
+VUE_APP_API_BASE_URL='/phmapi'
+# VUE_APP_API_BASE_URL=http://localhost:8867/jeecg-boot
 VUE_APP_CAS_BASE_URL=http://localhost:8888/cas
 VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview

+ 3 - 1
src/config/index.js

@@ -1,7 +1,9 @@
 /** init domain config */
 import Vue from 'vue'
 //设置全局API_BASE_URL
-Vue.prototype.API_BASE_URL = window._CONFIG.VUE_APP_API_BASE_URL?window._CONFIG.VUE_APP_API_BASE_URL:process.env.VUE_APP_API_BASE_URL
+// 部署修改
+Vue.prototype.API_BASE_URL = window._CONFIG.VUE_APP_API_BASE_URL?window._CONFIG.VUE_APP_API_BASE_URL:process.env.VUE_APP_API_BASE_URL + '/jeecg-boot'
+// Vue.prototype.API_BASE_URL = window._CONFIG.VUE_APP_API_BASE_URL?window._CONFIG.VUE_APP_API_BASE_URL:process.env.VUE_APP_API_BASE_URL
 window._CONFIG['domianURL'] = Vue.prototype.API_BASE_URL
 //单点登录地址
 window._CONFIG['casPrefixUrl'] = window._CONFIG.VUE_APP_CAS_BASE_URL?window._CONFIG.VUE_APP_CAS_BASE_URL:process.env.VUE_APP_CAS_BASE_URL

+ 1 - 1
src/utils/request.js

@@ -11,7 +11,7 @@ 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'];
 //console.log("apiBaseUrl= ",apiBaseUrl)
 // 创建 axios 实例
 const service = axios.create({

+ 6 - 2
vue.config.js

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