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
|
|
|
|
|
|
|
/**
|
|
|
|
* the host config data that NginxHost needs to create a valid instance
|
|
|
|
*/
|
2016-08-02 21:47:27 +00:00
|
|
|
export interface IHostConfigData {
|
2018-08-10 21:10:48 +00:00
|
|
|
hostName: string;
|
|
|
|
destination: string;
|
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
|
|
|
|
*/
|
|
|
|
export class NginxHost {
|
2018-08-10 21:10:48 +00:00
|
|
|
/**
|
|
|
|
* smartnginxInstance this NginHost belongs to
|
|
|
|
*/
|
|
|
|
smartnginxInstance: SmartNginx
|
|
|
|
|
|
|
|
hostName: string; // the host name e.g. domain name
|
|
|
|
destination: string;
|
|
|
|
configString: string; // the actual host config file as string
|
|
|
|
constructor(smartnginxInstanceArg: SmartNginx, optionsArg: IHostConfigData) {
|
|
|
|
this.smartnginxInstance = smartnginxInstanceArg;
|
|
|
|
this.hostName = optionsArg.hostName;
|
|
|
|
this.destination = optionsArg.destination;
|
|
|
|
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param certInstanceArg
|
|
|
|
*/
|
|
|
|
async deploy() {
|
|
|
|
let filePath = plugins.path.join(paths.nginxHostFileBase, this.hostName + '.conf');
|
|
|
|
// writeConfig
|
|
|
|
plugins.smartfile.memory.toFsSync(this.configString, filePath);
|
|
|
|
}
|
|
|
|
}
|