JavaScript代码
- proxy: {
- '/dev-api': {
- target: 'http://1x.xx.x.xxx:xxxx', //
- changeOrigin: true,
- pathRewrite: {
- '^/dev-api': ''
- },
- //第一种方法
- onProxyReq: function(proxyReq, req, res, options) {
- if (req.body) {
- const bodyData = JSON.stringify(req.body)
- // incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
- proxyReq.setHeader('Content-Type', 'application/json')
- proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
- // stream the content
- proxyReq.write(bodyData)
- }
- }
- }
- },
- //第二种方法,注释这行
- before: require('./mock/mock-server.js')