greenlock-store-fs.js/utils.js

52 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2019-11-02 18:38:12 +00:00
"use strict";
2019-10-27 10:01:42 +00:00
var U = module.exports;
// because not all file systems like '*' in a name (and they're scary)
U._tameWild = function tameWild(pathname, wild) {
2019-11-02 18:38:12 +00:00
if (!wild) {
return pathname;
}
var tame = wild.replace(/\*/g, "_");
return pathname.replace(wild, tame);
2019-10-27 10:01:42 +00:00
};
U._tpl = function tpl(store, opts, str) {
2019-11-02 18:38:12 +00:00
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) {
var item = opts[key] || store.options[key];
if ("string" !== typeof item) {
return;
}
2019-10-27 10:32:24 +00:00
2019-11-02 18:38:12 +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-11-02 18:38:12 +00:00
if (-1 === str.indexOf(":" + tmpl)) {
return;
}
str = str.replace(":" + tmpl, item);
});
});
});
return str;
2019-10-27 10:01:42 +00:00
};