2016-07-06 01:14:44 +00:00
|
|
|
import * as plugins from "./smartnginx.plugins";
|
2016-07-06 04:33:31 +00:00
|
|
|
import * as paths from "./smartnginx.paths";
|
|
|
|
import * as command from "./smartnginx.command";
|
2016-07-06 01:14:44 +00:00
|
|
|
|
|
|
|
export enum ZoneTypes {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-06 04:33:31 +00:00
|
|
|
let allConfigs:NginxConfig[] = [];
|
|
|
|
|
2016-07-06 01:14:44 +00:00
|
|
|
export class NginxConfig {
|
|
|
|
zones:NginxZone[];
|
2016-07-06 04:33:31 +00:00
|
|
|
isDeployed:boolean = false;
|
2016-07-06 01:14:44 +00:00
|
|
|
constructor(){
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// interact with Zones
|
|
|
|
addZone(zoneArg:NginxZone){
|
|
|
|
|
|
|
|
}
|
|
|
|
listZones():NginxZone[] {
|
|
|
|
return this.zones;
|
|
|
|
};
|
|
|
|
removeZones(zoneArg:NginxZone){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle deployment of zones
|
2016-07-06 04:33:31 +00:00
|
|
|
deploy(nginxRestartArg:boolean = false){
|
|
|
|
plugins.smartfile.fs.remove(paths.nginxZoneBase);
|
|
|
|
plugins.smartfile.fs.ensureDir(paths.nginxZoneBase);
|
|
|
|
for(let config of allConfigs){
|
|
|
|
config.isDeployed = false;
|
|
|
|
};
|
|
|
|
this.isDeployed = true;
|
|
|
|
for(let zone of this.zones){
|
|
|
|
zone.deploy();
|
|
|
|
}
|
|
|
|
if(nginxRestartArg){
|
|
|
|
command.restart(this);
|
|
|
|
}
|
2016-07-06 01:14:44 +00:00
|
|
|
};
|
2016-07-06 04:33:31 +00:00
|
|
|
|
2016-07-06 01:14:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export class NginxZone {
|
2016-07-06 04:33:31 +00:00
|
|
|
zoneName:string; // the zone name e.g. domain name
|
|
|
|
configString:string; // the actual zone config file as string
|
2016-07-06 01:14:44 +00:00
|
|
|
constructor(optionsArg:{
|
|
|
|
zoneName:string,
|
|
|
|
type:ZoneTypes,
|
|
|
|
destination:string
|
|
|
|
}){
|
|
|
|
|
2016-07-06 04:33:31 +00:00
|
|
|
};
|
|
|
|
deploy(){
|
|
|
|
let filePath = plugins.path.join(paths.nginxZoneBase,this.zoneName + ".conf");
|
|
|
|
plugins.smartfile.memory.toFsSync(this.configString,filePath);
|
|
|
|
};
|
2016-07-06 01:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let mynginx = new NginxConfig();
|