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. objective-c - ios百度地圖定位問題2. html5 - 如何解決bootstrap打開模態(tài)modal窗口引起頁面抖動?3. javascript - 求助關(guān)于js正則問題4. javascript - node.js服務(wù)端渲染解疑5. javascript - 求助這種功能有什么好點的插件?6. html5 - rudy編譯sass的時候有中文報錯7. html - css 如何添加這種邊框?8. 為何 localStorage、sessionStorage 屬于html5的范疇,但是為何 IE8卻支持?9. 微信開放平臺 - Android調(diào)用微信分享不顯示10. javascript - 關(guān)于定時器 與 防止連續(xù)點擊 問題
