2016-08-02 13:32:06 +00:00
|
|
|
import * as plugins from "./smartnginx.plugins";
|
|
|
|
import * as paths from "./smartnginx.paths";
|
|
|
|
import * as snippets from "./smartnginx.snippets"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the host config data that NginxHost needs to create a valid instance
|
|
|
|
*/
|
2016-08-02 21:47:27 +00:00
|
|
|
export interface IHostConfigData {
|
2016-08-02 13:32:06 +00:00
|
|
|
hostName: string,
|
|
|
|
type: hostTypes,
|
|
|
|
destination: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum hostTypes {
|
|
|
|
reverseProxy,
|
|
|
|
static
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* manages a single nginx host
|
|
|
|
*/
|
|
|
|
export class NginxHost {
|
|
|
|
hostName: string; // the host name e.g. domain name
|
|
|
|
type: hostTypes;
|
|
|
|
destination: string;
|
|
|
|
configString: string; // the actual host config file as string
|
2016-08-02 21:47:27 +00:00
|
|
|
constructor(optionsArg:IHostConfigData) {
|
2016-08-02 13:32:06 +00:00
|
|
|
this.hostName = optionsArg.hostName;
|
|
|
|
this.type = optionsArg.type;
|
|
|
|
this.destination = optionsArg.destination;
|
|
|
|
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
|
|
|
|
};
|
|
|
|
deploy(certInstanceArg: plugins.cert.Cert) {
|
|
|
|
let done = plugins.q.defer();
|
|
|
|
let filePath = plugins.path.join(paths.nginxHostFileBase, this.hostName + ".conf");
|
|
|
|
// writeConfig
|
|
|
|
plugins.smartfile.memory.toFsSync(this.configString, filePath);
|
|
|
|
// get cert
|
|
|
|
certInstanceArg.getDomainCert(this.hostName)
|
|
|
|
.then(done.resolve);
|
|
|
|
return done.promise;
|
|
|
|
};
|
|
|
|
};
|