Browse Source

dockerfile: 修改前端自动获取后端URL,避免重复打包问题

Yi 1 year ago
parent
commit
4d16104c4d
3 changed files with 48 additions and 73 deletions
  1. 3 26
      .env.development
  2. 1 7
      .env.production
  3. 44 40
      src/utils/request.js

+ 3 - 26
.env.development

@@ -4,33 +4,10 @@ ENV = 'development'
 # base api
 # 测试线
 
-# VUE_APP_BASE_API = 'http://192.168.1.70:8082/'
-
-#许义平本地
-VUE_APP_BASE_API = 'http://192.168.1.96:8082/'
-
-
-# VUE_APP_BASE_API = 'http://kpttest.kptyun.com/'
-# VUE_APP_BASE_API = 'http://kpttestnt.kptyun.com/'
-
-
-# VUE_APP_BASE_API = 'http://210.16.189.72:8081/'
-# VUE_APP_BASE_API = 'http://kpttest.kptyun.com/'
-# 南通测试线
-# VUE_APP_BASE_API = 'http://kpttestnt.kptyun.com/'
-
-# VUE_APP_BASE_API = 'http://tmrwatch.cn/'
-# 测试线
-# VUE_APP_BASE_API = 'http://tmrwatch.cn:8081/'
-
-# VUE_APP_BASE_API = 'http://127.0.0.1:8081/'
-
-# VUE_APP_BASE_API = 'http://lhpc81.kptyun.com/'
+# VUE_APP_BASE_API = 'http://192.168.1.70:8082/'
 
-
-
-# 白少杰
-VUE_APP_BASE_API = 'http://192.168.1.77:8081/'
+#许义平本地
+VUE_APP_BASE_API = 'http://192.168.1.70:8088/'
 
 # vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable,
 # to control whether the babel-plugin-dynamic-import-node plugin is enabled.

+ 1 - 7
.env.production

@@ -4,10 +4,4 @@ ENV = 'production'
 # base api
 # 正式线
 # VUE_APP_BASE_API = ':8081/'
-# VUE_APP_BASE_API = '/'
-# 测试线
-# VUE_APP_BASE_API = 'http://192.168.1.70:8083/'
-# VUE_APP_BASE_API = 'http://kpt8088.kptyun.com/'
-# VUE_APP_BASE_API = 'http://kpt8089.kptyun.com/'
-# VUE_APP_BASE_API = 'http://kpt8082.kptyun.com/'
-VUE_APP_BASE_API = 'http://kpt8083.kptyun.com/'
+VUE_APP_BASE_API = 'http://192.168.1.70:8088/'

+ 44 - 40
src/utils/request.js

@@ -2,21 +2,25 @@ import axios from 'axios'
 import { MessageBox, Message } from 'element-ui'
 import store from '@/store'
 import { getToken } from '@/utils/auth'
-
-//获取当前url
-
-var aa = process.env.VUE_APP_BASE_API
-//获取当前url
-
-if(aa.indexOf('/')==0 && aa.length==1){
-  aa= window.location.protocol + "//"+window.location.host+aa
-}
-  const service = axios.create({
-    baseURL: aa, // url = base url + request url
-    withCredentials: true, // send cookies when cross-domain requests
-    timeout: 60000 ,// request timeout
-  })
-// request interceptor
+
+//获取当前url
+const DoMainString = document.querySelector("html").getAttribute("domain");
+var URL = process.env.VUE_APP_BASE_API
+if (DoMainString) {
+  URL = DoMainString
+}
+
+console.log(URL,'===========URL')
+if(URL.indexOf('/')==0 && URL.length==1){
+  URL= window.location.protocol + "//"+window.location.host+aa
+}
+
+const service = axios.create({
+  baseURL: URL, // url = base url + request url
+  withCredentials: true, // send cookies when cross-domain requests
+  timeout: 60000 ,// request timeout
+})
+// request interceptor
 service.interceptors.request.use(
   config => {
     // do something before request is sent
@@ -35,7 +39,7 @@ service.interceptors.request.use(
       } else {
         config.headers['token'] = getToken()
       }
-    }
+    }
     return config
   },
   error => {
@@ -97,30 +101,30 @@ service.interceptors.response.use(
     }
   },
   error => {
-    console.log('err' + error) // for debug
-    let config = error.config
-    if (!config) {
-      Message({ message: error.message, type: 'error', duration: 5 * 1000 })
-      return Promise.reject(error)
-    }
-    console.log('config==>', config) // for debug
-    console.log('config.__retryCount==>', config.__retryCount) // for debug
-    // 设置请求超时次数
-    config.__retryCount = config.__retryCount || 0
-    if (config.__retryCount >= 3) {
-      // Message({ message:error.message, type: 'error', duration: 5 * 1000 })
-      Message({ message:'请求超时', type: 'error', duration: 5 * 1000 })
-      // Message.error((error && error.data && error.data.msg) || '请求超时')
-      return Promise.reject(error)
-    }
-    config.__retryCount += 1
-    let backoff = new Promise((resolve) => {
-      setTimeout(() => {
-        resolve()
-      }, config.retryDelay || 1000)
-    })
-    return backoff.then(() => {
-      return service(config)
+    console.log('err' + error) // for debug
+    let config = error.config
+    if (!config) {
+      Message({ message: error.message, type: 'error', duration: 5 * 1000 })
+      return Promise.reject(error)
+    }
+    console.log('config==>', config) // for debug
+    console.log('config.__retryCount==>', config.__retryCount) // for debug
+    // 设置请求超时次数
+    config.__retryCount = config.__retryCount || 0
+    if (config.__retryCount >= 3) {
+      // Message({ message:error.message, type: 'error', duration: 5 * 1000 })
+      Message({ message:'请求超时', type: 'error', duration: 5 * 1000 })
+      // Message.error((error && error.data && error.data.msg) || '请求超时')
+      return Promise.reject(error)
+    }
+    config.__retryCount += 1
+    let backoff = new Promise((resolve) => {
+      setTimeout(() => {
+        resolve()
+      }, config.retryDelay || 1000)
+    })
+    return backoff.then(() => {
+      return service(config)
     })
     // Message({
     //   message: error.message,