mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-17 23:45:29 -05:00
Merge pull request #254 from gbtechhub/fix-lb
fix running behind of loadbalancer with TLS termination
This commit is contained in:
commit
4829e5286e
2 changed files with 14 additions and 9 deletions
|
@ -45,8 +45,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 proto = req.get('X-Forwarded-Proto') || req.protocol;
|
||||
let base = Utils.combineBaseUrl(proto, req.get('host'), config.url_prefix);
|
||||
let base = Utils.combineBaseUrl(Utils.getWebProtocol(req), req.get('host'), config.url_prefix);
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
|
||||
storage.get_local(function(err, packages) {
|
||||
|
@ -111,17 +110,13 @@ module.exports = function(config, auth, storage) {
|
|||
res.cookies.set('token', auth.aes_encrypt(str).toString('base64'));
|
||||
}
|
||||
|
||||
let base = config.url_prefix
|
||||
? config.url_prefix.replace(/\/$/, '')
|
||||
: req.protocol + '://' + req.get('host');
|
||||
let base = Utils.combineBaseUrl(Utils.getWebProtocol(req), req.get('host'), config.url_prefix);
|
||||
res.redirect(base);
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/-/logout', function(req, res, next) {
|
||||
let base = config.url_prefix
|
||||
? config.url_prefix.replace(/\/$/, '')
|
||||
: req.protocol + '://' + req.get('host');
|
||||
let base = Utils.combineBaseUrl(Utils.getWebProtocol(req), req.get('host'), config.url_prefix);
|
||||
res.cookies.set('token', '');
|
||||
res.redirect(base);
|
||||
});
|
||||
|
|
12
lib/utils.js
12
lib/utils.js
|
@ -120,7 +120,7 @@ function filter_tarball_urls(pkg, req, config) {
|
|||
return _url;
|
||||
}
|
||||
const filename = URL.parse(_url).pathname.replace(/^.*\//, '');
|
||||
const base = combineBaseUrl(req.protocol, req.headers.host, config.url_prefix);
|
||||
const base = combineBaseUrl(getWebProtocol(req), req.headers.host, config.url_prefix);
|
||||
|
||||
return `${base}/${pkg.name.replace(/\//g, '%2f')}/-/${filename}`;
|
||||
};
|
||||
|
@ -314,6 +314,15 @@ function parseInterval(interval) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect running protocol (http or https)
|
||||
* @param {*} req
|
||||
* @return {String}
|
||||
*/
|
||||
function getWebProtocol(req) {
|
||||
return req.get('X-Forwarded-Proto') || req.protocol;
|
||||
}
|
||||
|
||||
module.exports.parseInterval = parseInterval;
|
||||
module.exports.semver_sort = semverSort;
|
||||
module.exports.parse_address = parse_address;
|
||||
|
@ -326,3 +335,4 @@ module.exports.validate_metadata = validate_metadata;
|
|||
module.exports.is_object = isObject;
|
||||
module.exports.validate_name = validate_name;
|
||||
module.exports.validate_package = validate_package;
|
||||
module.exports.getWebProtocol = getWebProtocol;
|
||||
|
|
Loading…
Add table
Reference in a new issue