diff --git a/lib/index-web.js b/lib/index-web.js index 5cb8c9c57..11faeb1f1 100644 --- a/lib/index-web.js +++ b/lib/index-web.js @@ -44,7 +44,7 @@ module.exports = function(config, auth, storage) { template = Handlebars.compile(fs.readFileSync(require.resolve('./GUI/index.hbs'), 'utf8')); } app.get('/', function(req, res, next) { - let base = Utils.get_base_url(req.protocol, req.get('host'), config.url_prefix); + let base = Utils.combineBaseUrl(req.protocol, req.get('host'), config.url_prefix); res.setHeader('Content-Type', 'text/html'); storage.get_local(function(err, packages) { diff --git a/lib/utils.js b/lib/utils.js index 5054cd0d4..3515f0ea6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -87,14 +87,14 @@ function validate_metadata(object, name) { * @param {String} prefix * @return {String} base registry url */ -function get_base_url(protocol, host, prefix) { - let result = protocol + '://' + host; +function combineBaseUrl(protocol, host, prefix) { + let result = '@{protocol}://@{host}'; if (prefix) { prefix = prefix.replace(/\/$/, ''); result = (prefix.indexOf('/') === 0) - ? result + prefix + ? '@{result}@{prefix}' : prefix; } @@ -119,7 +119,7 @@ function filter_tarball_urls(pkg, req, config) { return _url; } const filename = URL.parse(_url).pathname.replace(/^.*\//, ''); - const base = get_base_url(req.protocol, req.headers.host, config.url_prefix); + const base = combineBaseUrl(req.protocol, req.headers.host, config.url_prefix); return `${base}/${pkg.name.replace(/\//g, '%2f')}/-/${filename}`; }; @@ -280,7 +280,7 @@ module.exports.parse_address = parse_address; module.exports.get_version = get_version; module.exports.normalize_dist_tags = normalize_dist_tags; module.exports.tag_version = tag_version; -module.exports.get_base_url = get_base_url; +module.exports.combineBaseUrl = combineBaseUrl; module.exports.filter_tarball_urls = filter_tarball_urls; module.exports.validate_metadata = validate_metadata; module.exports.is_object = is_object;