實現代理服務器功能,可代理到http服務器與https服務器。vue
配置config/index.js
文件git
dev: { env: require('./dev.env'), port: 7090, autoOpenBrowser: true, assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api': { target: 'http://192.168.199.214:6481', changeOrigin: true }, } }
配置代理服務器處理302重定向的Responsegithub
dev: { env: require('./dev.env'), port: 7090, autoOpenBrowser: true, assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api': { target: 'http://192.168.199.214:6481', changeOrigin: true, onProxyRes: function(proxyRes, req, res) { if ([302].indexOf(proxyRes.statusCode) > -1 && proxyRes.headers.location) { var redirect = proxyRes.headers.location; console.log('Received code ' + proxyRes.statusCode + ' from API Server for URL - ' + redirect); redirect = redirect.replace('http://192.168.199.214:6481', 'http://localhost:7090'); console.log('Manipulating header location and redirecting to - ' + redirect); proxyRes.headers.location = redirect; } } }, } }