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’: ’’} }}
相關文章:
1. 關于docker下的nginx壓力測試2. javascript - webpack熱加載配置不生效3. debian - docker依賴的aufs-tools源碼哪里可以找到啊?4. 為什么我ping不通我的docker容器呢???5. angular.js - angular內容過長展開收起效果6. php - 一個操作請求多個服務如何保證數據的安全?7. javascript - js代碼獲取驗證碼倒計時問題8. 主從備份 - 跪求mysql 高可用主從方案9. docker start -a dockername 老是卡住,什么情況?10. dockerfile - [docker build image失敗- npm install]
