这是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.html
Request Method:GET
Status Code:502 Bad Gateway
Remote Address:[::1]:9999
Response Headers
view source
Connection:keep-alive
Content-Length:0
Date:Fri, 10 Mar 2017 06:56:20 GMT
X-Powered-By:Express
请问哪里配置错了吗
尝试让
webpak-dev-server
代理的请求加上 源host