Browse Source

跨域处理

yangc 6 years ago
parent
commit
86d085e5df
4 changed files with 24 additions and 23 deletions
  1. 1 12
      components/mobile/staffManagement/StaffList.vue
  2. 3 0
      nuxt.config.js
  3. 11 11
      plugins/axios.js
  4. 9 0
      server.js

+ 1 - 12
components/mobile/staffManagement/StaffList.vue

@@ -129,18 +129,7 @@
     methods: {
       setSwitchType (type) {
         this.switchType = type
-        // this.$jsonp(`${process.env.ssoUrl}/api/userspace/apply/info/mall?count=10&page=1&speaceUU=10049698&status=311`, {timeout: 5000, name: 'successCallback'}, (err, data) => {
-        //   console.log(err, data, '231')
-        // })
-        this.$http({
-          method: 'get',
-          dataType: 'jsonp',
-          url: `${process.env.ssoUrl}/api/userspace/apply/info/mall?count=10&page=1&speaceUU=10049698&status=311`
-        }).then(res => {
-            console.log('1', res.data)
-          }, err => {
-            console.log('12', err)
-          })
+        this.$http.get('/api/userspace/apply/info/mall?count=10&page=1&speaceUU=10049698&status=311')
       }
     }
   }

+ 3 - 0
nuxt.config.js

@@ -138,6 +138,9 @@ module.exports = {
    *   }
    */
   proxyTable: {
+    // 账户中心统一前缀
+    '/ssoPrefix/**': ssoUrl,
+    '/api/userspace/**': ssoUrl,
     '/api/**': baseUrl,
     '/search/**': baseUrl,
     '/user/**': baseUrl,

+ 11 - 11
plugins/axios.js

@@ -22,20 +22,20 @@ service.interceptors.request.use(config => {
       config.url = process.env.messageUrl + config.url
     } else if (config.url.indexOf('/cmsApi') === 0) {
       config.url = process.env.cmsUrl + config.url
-    // } else if (config.url.indexOf('/sso') === 0) {
-    //   config.url = process.env.ssoUrl + config.url
+    } else if (config.url.indexOf('/sso') === 0) {
+      config.url = process.env.ssoUrl + config.url
     } else {
       config.url = process.env.baseUrl + config.url
     }
-  //   let paramStr = ''
-  //   if (config.params) {
-  //     paramStr += '?'
-  //     for (let s in config.params) {
-  //       paramStr += s + '=' + config.params[s] + '&'
-  //     }
-  //     paramStr.substr(0, paramStr.length - 2)
-  //   }
-  //   console.log(config.url + paramStr)
+    //   let paramStr = ''
+    //   if (config.params) {
+    //     paramStr += '?'
+    //     for (let s in config.params) {
+    //       paramStr += s + '=' + config.params[s] + '&'
+    //     }
+    //     paramStr.substr(0, paramStr.length - 2)
+    //   }
+    //   console.log(config.url + paramStr)
     // config.headers.cookie = store.state.option.cookies + '; ' + store.state.option.sessionId
     // config.headers['User-Agent']
   } else {

+ 9 - 0
server.js

@@ -24,6 +24,15 @@ process.noDeprecation = true
 //   next()
 // })
 
+// 账户中心接口统一处理
+app.get('/ssoPrefix/**', (req, res, next) => {
+  req.url = req.url.replace('/ssoPrefix', '')
+  console.log(req.url)
+  res.redirect(req.url.replace('/ssoPrefix', ''))
+  // req.config.url = req.config.url.replace('/ssoPrefix', '')
+  next()
+})
+
 app.set('port', port)
 
 // Import and Set Nuxt.js options