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. 我的html頁面一提交,網頁便顯示出了我的php代碼,求問是什么原因?2. django - 后臺返回的json數據經過Base64加密,獲取時用python如何解密~!3. tp6表單令牌4. 我在centos容器里安裝docker,也就是在容器里安裝容器,報錯了?5. node.js - node 客戶端socket一直報錯Error: read ECONNRESET,用php的socket沒問題哈。。6. docker 17.03 怎么配置 registry mirror ?7. 老哥們求助啊8. node.js - nodejs中把熱request保存下來,使用JSON.stringify(req)報錯,請問怎么解決?9. mysql分庫分表量級疑問10. javascript - canvas 可以實現 PS 魔法橡皮擦的功能嗎?
