const oUrl = require("url");
//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>
nodejs http2https hbs
原文地址:https://www.cnblogs.com/limingziqiang/p/8580657.html