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-compose中volumes的問(wèn)題2. golang - 用IDE看docker源碼時(shí)的小問(wèn)題3. dockerfile - [docker build image失敗- npm install]4. angular.js - angular內(nèi)容過(guò)長(zhǎng)展開(kāi)收起效果5. mysql函數(shù)unix_timestamp如何處理1970.1.1以前的數(shù)據(jù)?6. 表單提交驗(yàn)證,沒(méi)反應(yīng),求老師指點(diǎn)7. mysql - 記錄開(kāi)始時(shí)間和結(jié)束時(shí)間,表字段類(lèi)型用timestamp還是datetime?8. javascript - js代碼轉(zhuǎn)python9. 老師,樣式?jīng)]有變呀?10. MySQL 什么需求下(情況下)才使用事務(wù)?

網(wǎng)公網(wǎng)安備