smartnginx/dist/smartnginx.classes.nginxconfig.js

71 lines
4.9 KiB
JavaScript
Raw Permalink Normal View History

2016-07-06 01:14:44 +00:00
"use strict";
2016-07-21 00:24:54 +00:00
const plugins = require("./smartnginx.plugins");
const paths = require("./smartnginx.paths");
const snippets = require("./smartnginx.snippets");
2016-07-24 23:54:36 +00:00
const smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
2016-07-21 00:24:54 +00:00
let allConfigs = [];
/**
* main class that manages a NginxInstance
*/
2016-07-21 00:24:54 +00:00
class NginxConfig {
constructor(optionsArg) {
this.hosts = [];
2016-07-24 23:54:36 +00:00
this.nginxProcess = new smartnginx_classes_nginxprocess_1.NginxProcess(this);
2016-07-06 04:33:31 +00:00
this.isDeployed = false;
2016-07-12 21:20:08 +00:00
this.cert = new plugins.cert.Cert({
cfEmail: optionsArg.cfEmail,
cfKey: optionsArg.cfKey,
sslDir: paths.nginxCertBase,
gitOriginRepo: optionsArg.gitOriginRepo,
testMode: optionsArg.testMode
2016-07-12 21:20:08 +00:00
});
2016-07-06 01:14:44 +00:00
}
;
// interact with Hosts
addHost(nginxHostArg) {
this.hosts.push(nginxHostArg);
2016-07-21 00:24:54 +00:00
}
listHosts() {
return this.hosts;
2016-07-21 00:24:54 +00:00
}
2016-07-06 01:33:39 +00:00
;
removeHost(nginxHostArg) {
2016-07-21 00:24:54 +00:00
}
clean() {
this.hosts = [];
2016-07-21 00:24:54 +00:00
}
// handle deployment of hosts
2016-07-24 23:54:36 +00:00
deploy() {
2016-07-21 00:24:54 +00:00
let done = plugins.q.defer();
2016-07-08 02:24:07 +00:00
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxHostFileBase);
2016-07-12 21:20:08 +00:00
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
2016-07-21 00:24:54 +00:00
for (let config of allConfigs) {
2016-07-06 04:33:31 +00:00
config.isDeployed = false;
}
;
this.isDeployed = true;
2016-07-12 21:20:08 +00:00
// write base config
2016-07-24 23:54:36 +00:00
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
// deploy hosts
2016-07-21 00:24:54 +00:00
let promiseArray = [];
for (let host of this.hosts) {
let hostDeployedPromise = host.deploy(this.cert);
hostDeployedPromise.then(() => {
plugins.beautylog.info(`Host ${host.hostName} deployed!`);
2016-07-24 23:54:36 +00:00
this.nginxProcess.reloadConfig();
});
promiseArray.push(hostDeployedPromise);
2016-07-06 04:33:31 +00:00
}
2016-07-08 02:24:07 +00:00
;
2016-07-12 21:20:08 +00:00
plugins.q.all(promiseArray)
2016-07-21 00:24:54 +00:00
.then(() => {
2016-07-12 21:20:08 +00:00
done.resolve();
});
return done.promise;
2016-07-21 00:24:54 +00:00
}
2016-07-06 01:14:44 +00:00
;
2016-07-21 00:24:54 +00:00
}
2016-07-06 01:14:44 +00:00
exports.NginxConfig = NginxConfig;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELE1BQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsTUFBWSxRQUFRLFdBQU0sdUJBQXVCLENBQUMsQ0FBQTtBQUVsRCxrREFBNkIsbUNBQW1DLENBQUMsQ0FBQTtBQUNqRSxJQUFJLFVBQVUsR0FBa0IsRUFBRSxDQUFDO0FBRW5DOztHQUVHO0FBQ0g7SUFLSSxZQUFZLFVBQWdEO1FBSjVELFVBQUssR0FBZ0IsRUFBRSxDQUFDO1FBRXhCLGlCQUFZLE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