node.js - webpack-dev-server配置proxy一直报502
问题描述
这是webpack-dev-server的配置:
var server = new WebpackDevServer(webpack(config), { publicPath: ’http://localhost:9999/’, hot: true, prependPath: false, historyApiFallback: true, inline: true, progress: true, stats: {colors: true }, proxy: {’/api/*’: { target: ’http://www.weather.com.cn’, secure: false, pathRewrite: {’^/api’: ’’}} }});
这是ajax请求:
$.ajax({ url: ’/api/data/sk/101010100.html’, type: ’get’, dataType: ’json’, success: function (data) {console.log(data); }});
这是浏览器请求的信息:
Request URL:http://localhost:9999/api/data/sk/101010100.htmlRequest Method:GETStatus Code:502 Bad GatewayRemote Address:[::1]:9999Response Headersview sourceConnection:keep-aliveContent-Length:0Date:Fri, 10 Mar 2017 06:56:20 GMTX-Powered-By:Express
请问哪里配置错了吗
问题解答
回答1:尝试让webpak-dev-server 代理的请求加上 源host
proxy: { // 尝试修改下匹配 ’/api’: {target: ’http://www.weather.com.cn’,secure: false,// 新增一行changeOrigin: true,pathRewrite: {’^/api’: ’’} }}
相关文章:
1. angular.js - Web应用,单页面应用Cache问题2. angular.js - angular post的Content-Type被设置,导致不能上传图片,求助!!3. android - webview 自定义加载进度条4. css3 - 这个效果用 CSS 可以实现吗?border-image5. Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?6. javascript - echart2.0 饼图不能自适应???7. javascript - vue更改当前节点元素8. vue.js - vue 打包后 nginx 服务端API请求跨域问题无法解决。9. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?10. position:absolute、float、display:inline-block 都能实现相同效果,区别是什么?

网公网安备