node.js - webpack-dev-server配置proxy一直報(bào)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請(qǐng)求:
$.ajax({ url: ’/api/data/sk/101010100.html’, type: ’get’, dataType: ’json’, success: function (data) {console.log(data); }});
這是瀏覽器請(qǐng)求的信息:
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
請(qǐng)問哪里配置錯(cuò)了嗎
問題解答
回答1:嘗試讓webpak-dev-server 代理的請(qǐng)求加上 源host
proxy: { // 嘗試修改下匹配 ’/api’: {target: ’http://www.weather.com.cn’,secure: false,// 新增一行changeOrigin: true,pathRewrite: {’^/api’: ’’} }}
相關(guān)文章:
1. pip安裝提示Twisted錯(cuò)誤問題(Python3.6.4安裝Twisted錯(cuò)誤)2. javascript - 關(guān)于css絕對(duì)定位在ios瀏覽器被橡皮筋遮擋的問題3. 關(guān)于Mysql聯(lián)合查詢4. centos7 編譯安裝 Python 3.5.1 失敗5. mysql - 這個(gè)數(shù)據(jù)庫合計(jì)用 視圖做,和直接算好存在數(shù)據(jù)庫里,到時(shí)候調(diào)用起來哪個(gè)快?6. python - beautifulsoup獲取網(wǎng)頁內(nèi)容的問題7. python - 能通過CAN控制一部普通的家用轎車嗎?8. 人工智能 - python 機(jī)器學(xué)習(xí) 醫(yī)療數(shù)據(jù) 怎么學(xué)9. mysql - 分庫分表、分區(qū)、讀寫分離 這些都是用在什么場(chǎng)景下 ,會(huì)帶來哪些效率或者其他方面的好處10. c++ - 請(qǐng)問MySQL_Connection::isReadOnly 怎么解決?
