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. dockerfile - 我用docker build的时候出现下边问题 麻烦帮我看一下2. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?3. dockerfile - 为什么docker容器启动不了?4. angular.js使用$resource服务把数据存入mongodb的问题。5. javascript - JS用ajax爬取百度外卖店家信息6. 在应用配置文件 app.php 中找不到’route_check_cache’配置项7. 我在centos容器里安装docker,也就是在容器里安装容器,报错了?8. java - 为什么第一个线程已经释放了锁,第二个线程却不行?9. javascript - 编程,算法的问题10. docker - 如何修改运行中容器的配置

网公网安备