JavaScript代码
  1. proxy: {  
  2.     '/dev-api': {  
  3.         target: 'http://1x.xx.x.xxx:xxxx', //  
  4.         changeOrigin: true,  
  5.         pathRewrite: {  
  6.           '^/dev-api': ''  
  7.         },  
  8.         //第一种方法  
  9.         onProxyReq: function(proxyReq, req, res, options) {  
  10.           if (req.body) {  
  11.             const bodyData = JSON.stringify(req.body)  
  12.             // incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json  
  13.             proxyReq.setHeader('Content-Type', 'application/json')  
  14.             proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))  
  15.             // stream the content  
  16.             proxyReq.write(bodyData)  
  17.           }  
  18.        }  
  19.    }  
  20. },  
  21. //第二种方法,注释这行  
  22. before: require('./mock/mock-server.js')  
vue | 评论(0) | 引用(0) | 阅读(472)