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’: ’’} }}
相關(guān)文章:
1. javascript - 一個是數(shù)組,一個是對象,怎么進(jìn)行比較去重?2. android - 有沒有比較好的類似微信拍攝小視頻那樣的demo3. 黑客 - Python模塊安全權(quán)限4. docker - 如何修改運(yùn)行中容器的配置5. html5 - bootstrap修改樣式的問題6. android - 像支付寶到位這種點(diǎn)擊marker點(diǎn)擊變大怎么做的7. npm鏡像站全新上線8. utf-8 - python在windows命令行下生成文件亂碼問題,如何解決?9. javascript - 關(guān)于ios微信端瀏覽器網(wǎng)頁的一些問題10. css - input間的間距和文字上下居中
