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請求:
$.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
請問哪里配置錯(cuò)了嗎
問題解答
回答1:嘗試讓webpak-dev-server 代理的請求加上 源host
proxy: { // 嘗試修改下匹配 ’/api’: {target: ’http://www.weather.com.cn’,secure: false,// 新增一行changeOrigin: true,pathRewrite: {’^/api’: ’’} }}
相關(guān)文章:
1. docker內(nèi)創(chuàng)建jenkins訪問另一個(gè)容器下的服務(wù)器問題2. 如何解決Centos下Docker服務(wù)啟動(dòng)無響應(yīng),且輸入docker命令無響應(yīng)?3. node.js - 如何避免 webstorm 中 Vue 項(xiàng)目通過 npm 面板運(yùn)行開發(fā)服務(wù)器時(shí)的 DEBUG_FD 已廢棄提示信息4. 老師您的微信號(hào)是多少?5. vim里的高亮javascript的javascript.vim 已經(jīng)放到syntax里了,但是不行。6. 我在centos容器里安裝docker,也就是在容器里安裝容器,報(bào)錯(cuò)了?7. html5 - 百度echart官網(wǎng)下載的地圖json數(shù)據(jù)亂碼8. css3 - 學(xué)習(xí)css構(gòu)建圖形時(shí),遇到一個(gè)很有意思的現(xiàn)象,具體代碼如下9. 極光推送 - Android app消息推送 百度 極光 個(gè)推 信鴿哪個(gè)好一些?10. vue ajax請求回來的數(shù)據(jù)沒有渲染到頁面
