Files
smartnginx/ts/smartnginx.classes.nginxhost.ts

63 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

2023-07-26 16:05:53 +02:00
import * as plugins from './smartnginx.plugins.js';
import * as paths from './smartnginx.paths.js';
import * as snippets from './smartnginx.snippets.js';
2023-07-26 16:05:53 +02:00
import { SmartNginx } from './smartnginx.classes.smartnginx.js';
2023-07-26 16:05:53 +02:00
import { type IHostConfig } from './interfaces/hostconfig.js';
export enum hostTypes {
2023-07-26 16:05:53 +02:00
reverseProxy,
}
/**
* manages a single nginx host
*/
2019-01-09 12:15:28 +01:00
export class NginxHost implements IHostConfig {
/**
* smartnginxInstance this NginHost belongs to
*/
2019-01-18 00:45:29 +01:00
public smartnginxInstance: SmartNginx;
2019-01-18 00:45:29 +01:00
public hostName: string; // the host name e.g. domain name
public destination: string;
2019-01-19 15:41:51 +01:00
public destinationPort: number;
2019-01-18 00:45:29 +01:00
public configString: string; // the actual host config file as string
public privateKey: string;
public publicKey: string;
2019-01-09 12:15:28 +01:00
constructor(smartnginxInstanceArg: SmartNginx, optionsArg: IHostConfig) {
this.smartnginxInstance = smartnginxInstanceArg;
this.hostName = optionsArg.hostName;
this.destination = optionsArg.destination;
2019-01-19 15:41:51 +01:00
this.destinationPort = optionsArg.destinationPort;
2019-01-09 14:10:57 +01:00
this.privateKey = optionsArg.privateKey;
this.publicKey = optionsArg.publicKey;
}
/**
*
* @param certInstanceArg
*/
2019-01-09 12:15:28 +01:00
public async deploy() {
2019-08-20 22:30:31 +02: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`);
2019-01-19 15:41:51 +01:00
// writeConfig
2019-08-20 22:30:31 +02:00
this.configString = snippets.getHostConfigString(
this.hostName,
this.destination,
this.destinationPort
);
2019-01-09 14:10:57 +01:00
plugins.smartfile.memory.toFsSync(this.configString, filePathConfig);
// write ssl
plugins.smartfile.memory.toFsSync(this.privateKey, filePathPrivate);
plugins.smartfile.memory.toFsSync(this.publicKey, filePathPublic);
}
}