greenlock-store-fs.js/utils.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-10-27 10:01:42 +00:00
'use strict';
var U = module.exports;
// because not all file systems like '*' in a name (and they're scary)
U._tameWild = function tameWild(pathname, wild) {
if (!wild) {
return pathname;
}
var tame = wild.replace(/\*/g, '_');
return pathname.replace(wild, tame);
};
U._tpl = function tpl(store, opts, str) {
var server = ['directoryUrl', 'serverDir', 'server'];
var env = ['env', 'directoryUrl'];
[
['basePath', 'configDir'],
server,
['subject', 'hostname', 'domain'],
env
].forEach(function(group) {
group.forEach(function(tmpl) {
group.forEach(function(key) {
2019-10-27 10:32:24 +00:00
var item = opts[key] || store.options[key];
if ('string' !== typeof item) {
return;
}
2019-10-27 10:01:42 +00:00
if ('directoryUrl' === key) {
item = item.replace(/^https?:\/\//i, '');
}
if ('env' === tmpl) {
if (/staging/.test(item)) {
item = 'staging';
} else if (/acme-v02/.test(item)) {
item = 'live';
} else {
// item = item;
}
}
2019-10-27 10:32:24 +00:00
2019-10-27 10:01:42 +00:00
if (-1 === str.indexOf(':' + tmpl)) {
return;
}
str = str.replace(':' + tmpl, item);
});
});
});
return str;
};