Browse Source

修改配置

yingp 8 years ago
parent
commit
77a109bcaa
2 changed files with 5 additions and 1 deletions
  1. 4 0
      plugins/axios.js
  2. 1 1
      server.js

+ 4 - 0
plugins/axios.js

@@ -6,6 +6,10 @@ const service = axios.create({
 })
 
 service.interceptors.request.use(config => {
+  // is server render, use ${baseUrl} directly rather than ${proxyUrl}
+  if (process.env.proxyUrl && typeof window === 'undefined') {
+    config.url = process.env.baseUrl + config.url
+  }
   return config
 }, error => {
   return Promise.reject(error)

+ 1 - 1
server.js

@@ -37,7 +37,7 @@ if (config.dev && proxyTable) {
     })
   }
   // axios use proxy url
-  config.env.proxyUrl = `http://${host}:${port}/`
+  config.env.proxyUrl = '/'
 }
 
 // Init Nuxt.js