mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-20 22:52:46 -05:00
Allow url_prefix to be only the path
* Define utils function `get_base_url`. * If url_prefix start with `/` construct base URL using protocol and host form request. * Update SERVER.md with description of new `url_prefix` option.
This commit is contained in:
parent
93bea50176
commit
ff05d779c4
3 changed files with 33 additions and 10 deletions
|
@ -28,6 +28,12 @@ url_prefix: 'https://your-domain:8888'
|
|||
# or
|
||||
url_prefix: 'https://your-domain:8888/your-path'
|
||||
```
|
||||
|
||||
If you do not know the protocol and host, you can define only subpath as `url_prefix`. Full URL will be constructed from the request.
|
||||
```yaml
|
||||
url_prefix: '/your-path'
|
||||
```
|
||||
|
||||
> Nginx or Apache configure? Please check out Wiki ;-)
|
||||
|
||||
## Keeping verdaccio running forever
|
||||
|
|
|
@ -9,6 +9,7 @@ let Handlebars = require('handlebars');
|
|||
let renderReadme = require('render-readme');
|
||||
let Search = require('./search');
|
||||
let Middleware = require('./middleware');
|
||||
let Utils = require('./utils');
|
||||
let match = Middleware.match;
|
||||
let validate_name = Middleware.validate_name;
|
||||
let validate_pkg = Middleware.validate_package;
|
||||
|
@ -43,9 +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 = config.url_prefix
|
||||
? config.url_prefix.replace(/\/$/, '')
|
||||
: req.protocol + '://' + req.get('host');
|
||||
let base = Utils.get_base_url(req.protocol, req.get('host'), config.url_prefix);
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
|
||||
storage.get_local(function(err, packages) {
|
||||
|
|
32
lib/utils.js
32
lib/utils.js
|
@ -80,6 +80,27 @@ function validate_metadata(object, name) {
|
|||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create base url for registry.
|
||||
* @param {String} protocol
|
||||
* @param {String} host
|
||||
* @param {String} prefix
|
||||
* @return {String} base registry url
|
||||
*/
|
||||
function get_base_url(protocol, host, prefix) {
|
||||
let result = protocol + '://' + host;
|
||||
|
||||
if (prefix) {
|
||||
prefix = prefix.replace(/\/$/, '');
|
||||
|
||||
result = (prefix.indexOf('/') === 0)
|
||||
? result + prefix
|
||||
: prefix;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate a packages's versions and filter each original tarbal url.
|
||||
* @param {*} pkg
|
||||
|
@ -98,13 +119,9 @@ function filter_tarball_urls(pkg, req, config) {
|
|||
return _url;
|
||||
}
|
||||
const filename = URL.parse(_url).pathname.replace(/^.*\//, '');
|
||||
let result;
|
||||
if (config.url_prefix != null) {
|
||||
result = config.url_prefix.replace(/\/$/, '');
|
||||
} else {
|
||||
result = `${req.protocol}://${req.headers.host}`;
|
||||
}
|
||||
return `${result}/${pkg.name.replace(/\//g, '%2f')}/-/${filename}`;
|
||||
const base = get_base_url(req.protocol, req.headers.host, config.url_prefix);
|
||||
|
||||
return `${base}/${pkg.name.replace(/\//g, '%2f')}/-/${filename}`;
|
||||
};
|
||||
|
||||
for (let ver in pkg.versions) {
|
||||
|
@ -263,6 +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.filter_tarball_urls = filter_tarball_urls;
|
||||
module.exports.validate_metadata = validate_metadata;
|
||||
module.exports.is_object = is_object;
|
||||
|
|
Loading…
Add table
Reference in a new issue