node.js - webpack-dev-server配置proxy一直報(bào)502
問(wèn)題描述
這是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)問(wèn)哪里配置錯(cuò)了嗎
問(wèn)題解答
回答1:嘗試讓webpak-dev-server 代理的請(qǐng)求加上 源host
proxy: { // 嘗試修改下匹配 ’/api’: {target: ’http://www.weather.com.cn’,secure: false,// 新增一行changeOrigin: true,pathRewrite: {’^/api’: ’’} }}
相關(guān)文章:
1. 如何解決docker宿主機(jī)無(wú)法訪問(wèn)容器中的服務(wù)?2. javascript - 如何使用nodejs 將.html 文件轉(zhuǎn)化成canvas3. angular.js - 輸入郵箱地址之后, 如何使其自動(dòng)在末尾添加分號(hào)?4. javascript - html5的data屬性怎么指定一個(gè)function函數(shù)呢?5. 在mac下出現(xiàn)了兩個(gè)docker環(huán)境6. python - Scrapy存在內(nèi)存泄漏的問(wèn)題。7. java如何生成token?8. docker-compose中volumes的問(wèn)題9. javascript - 后臺(tái)管理系統(tǒng)左側(cè)折疊導(dǎo)航欄數(shù)據(jù)較多,怎么樣直接通過(guò)搜索去定位到具體某一個(gè)菜單項(xiàng)位置,并展開(kāi)當(dāng)前菜單10. javascript - Web微信聊天輸入框解決方案
