2018-08-10 21:10:48 +00:00
|
|
|
import * as plugins from './smartnginx.plugins';
|
|
|
|
import * as paths from './smartnginx.paths';
|
|
|
|
import * as snippets from './smartnginx.snippets';
|
|
|
|
|
|
|
|
import { SmartNginx } from './smartnginx.classes.smartnginx';
|
2016-08-02 13:32:06 +00:00
|
|
|
|
2019-01-09 11:15:28 +00:00
|
|
|
import { IHostConfig } from './interfaces/hostconfig';
|
2016-08-02 13:32:06 +00:00
|
|
|
|
|
|
|
export enum hostTypes {
|
2018-08-10 21:10:48 +00:00
|
|
|
reverseProxy
|
2016-08-02 13:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* manages a single nginx host
|
|
|
|
*/
|
2019-01-09 11:15:28 +00:00
|
|
|
export class NginxHost implements IHostConfig {
|
|
|
|
/**
|
2018-08-10 21:10:48 +00:00
|
|
|
* smartnginxInstance this NginHost belongs to
|
|
|
|
*/
|
2019-01-17 23:45:29 +00:00
|
|
|
public smartnginxInstance: SmartNginx;
|
2018-08-10 21:10:48 +00:00
|
|
|
|
2019-01-17 23:45:29 +00:00
|
|
|
public hostName: string; // the host name e.g. domain name
|
|
|
|
public destination: string;
|
|
|
|
public configString: string; // the actual host config file as string
|
|
|
|
public privateKey: string;
|
|
|
|
public publicKey: string;
|
2019-01-09 11:15:28 +00:00
|
|
|
|
|
|
|
constructor(smartnginxInstanceArg: SmartNginx, optionsArg: IHostConfig) {
|
2018-08-10 21:10:48 +00:00
|
|
|
this.smartnginxInstance = smartnginxInstanceArg;
|
|
|
|
this.hostName = optionsArg.hostName;
|
|
|
|
this.destination = optionsArg.destination;
|
|
|
|
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
|
2019-01-09 13:10:57 +00:00
|
|
|
this.privateKey = optionsArg.privateKey;
|
|
|
|
this.publicKey = optionsArg.publicKey;
|
2018-08-10 21:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param certInstanceArg
|
|
|
|
*/
|
2019-01-09 11:15:28 +00:00
|
|
|
public async deploy() {
|
2019-01-09 13:10:57 +00:00
|
|
|
const filePathConfig = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.conf`);
|
|
|
|
const filePathPrivate = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.private.pem`);
|
|
|
|
const filePathPublic = plugins.path.join(paths.nginxHostDirPath, `${this.hostName}.public.pem`);
|
2018-08-10 21:10:48 +00:00
|
|
|
// writeConfig
|
2019-01-09 13:10:57 +00:00
|
|
|
plugins.smartfile.memory.toFsSync(this.configString, filePathConfig);
|
|
|
|
|
|
|
|
// write ssl
|
|
|
|
plugins.smartfile.memory.toFsSync(this.privateKey, filePathPrivate);
|
|
|
|
plugins.smartfile.memory.toFsSync(this.publicKey, filePathPublic);
|
|
|
|
|
2018-08-10 21:10:48 +00:00
|
|
|
}
|
|
|
|
}
|