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. css - 关于HTML中width和height的疑问(这个提问的标题不好起)2. javascript - 在 model里定义的 引用表模型时,model为undefined。3. HTML5表单必填属性设置自定义验证消息?4. mysql - 求一个sql语句,比较简单。5. 在mac下出现了两个docker环境6. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?7. html5 - bootstrap修改样式的问题8. java - 如图,jsp页面的form中的action是怎么映射到这个位置的?为什么不写dynUser就可以映射到save?9. java - 接口中的成员变量怎么不是常量了?10. javascript - 清空Chrome缓存的疑问

网公网安备