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 - angularjs的自定义过滤器如何给文字加颜色?2. docker安装后出现Cannot connect to the Docker daemon.3. android - 启动模拟器的,报“Could not automatically detect an ADB binary……”,要怎么解决?4. python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)5. 关于Java引用传递的一个困惑?6. 如何分别在Windows下用Winform项模板+C#,在MacOSX下用Cocos Application项目模板+Objective-C实现一个制作游戏的空的黑窗口?7. 关于docker下的nginx压力测试8. android clickablespan获取选中内容9. javascript - 最终生成的jsBundle文件压缩问题10. node.js - 如何在服务器部署vuejs项目?
