nodejs http2https hbs

//get 请求外网  
function loadPage(url) {
    var http = require('http');
    var pm = new Promise(function (resolve, reject) {
        http.get(url, function (res) {
            var html = '';
            res.on('data', function (d) {
                html += d.toString()
            });
            res.on('end', function () {
                resolve(html);
            });
        }).on('error', function (e) {
            reject(e)
        });
    });
    return pm;
}
 
hbs.registerHelper('http2https', function(url){
	var sUrl = '/http2https/s?='+url;
	return sUrl;
});
 

router.get('/http2https/*',function(req,res,next){ var url = req.originalUrl.replace('/http2https/s?=',''); loadPage(url).then(function(d) { res.write(d); res.end(); }); });

 页面调用 <script src="{{http2https 'http://min.static.xxx.com/min/?f=static/site/asset/script/xxx/common-min.js'}}"></script>

posted @ 2018-03-16 13:44  熊二(李明)  阅读(695)  评论(0编辑  收藏  举报