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. javascript - 關于<a>元素與<input>元素的JS事件運行問題2. android下css3動畫非常卡,GPU也不差啊3. MySQL中的enum類型有什么優點?4. css3 - 純css實現點擊特效5. mysql - 記得以前在哪里看過一個估算時間的網站6. javascript - vue 怎么渲染自定義組件7. mysql - 查詢字段做了索引為什么不起效,還有查詢一個月的時候數據都是全部出來的,如果分拆3次的話就沒問題,為什么呢。8. ID主鍵不是自增的嗎 為什么還要加null9. python - 啟動Eric6時報錯:’qscintilla_zh_CN’ could not be loaded10. css - 新手做響應式布局, 斷點過后右側出現空白,求幫助,謝謝。
