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 - 求推薦幾款好用的移動端頁面布局調試工具呢?2. javascript - 百度echarts series數據更新問題3. css3 - 手機網頁中用css寫1px的描邊,為什么需要加一句overflow:hidden才能真正顯示1px?4. php - 第三方支付平臺在很短時間內多次異步通知,訂單多次確認收款5. Mysql && Redis 并發問題6. javascript - node服務端渲染的困惑7. css3 - css before 中文亂碼?8. mysql - 一個表和多個表是多對多的關系,該怎么設計9. python - type函數問題10. mysql新建字段時 timestamp NOT NULL DEFAULT ’0000-00-00 00:00:00’ 報錯
