Compare commits
68 Commits
Author | SHA1 | Date | |
---|---|---|---|
b4ebdbae47 | |||
c55d2dcf10 | |||
7274d5ea8a | |||
1ec733c2a9 | |||
3ef14d8ac7 | |||
f332bf95fe | |||
6acad8a306 | |||
6ae672f707 | |||
3d263e2181 | |||
85639f29af | |||
85448a21fc | |||
3b85c4a37e | |||
67dd650dce | |||
92eaf5f19a | |||
fcf9a61b1d | |||
fbd258a876 | |||
c65b8fc1af | |||
b7b588d713 | |||
00d672c135 | |||
6a1e778b49 | |||
4cfb26f62f | |||
7ba3ad0b21 | |||
cd93ec2560 | |||
ede884930e | |||
1049920efd | |||
b7a34403c5 | |||
987e19372a | |||
0b97aaee91 | |||
b87ca1fa03 | |||
824f872fa5 | |||
80248c77d0 | |||
f592150646 | |||
f24652936a | |||
79af6c4a68 | |||
fafc757930 | |||
ead5e1a7bd | |||
ad57be180a | |||
7cc4ce02c9 | |||
70dace595b | |||
9b043d0e0d | |||
381227406b | |||
08d1c292c3 | |||
64b0a2deb7 | |||
9b661c0ee5 | |||
8ca91a48e8 | |||
39a5683b9e | |||
7967334e7d | |||
5a875d1e22 | |||
4c68d27b6d | |||
1cca4f95bc | |||
3cef614bb3 | |||
c3c2ab776d | |||
a533fa5de1 | |||
d8a4c3d088 | |||
e2639fd0a9 | |||
b5a27d5108 | |||
f32002309d | |||
52c3b40879 | |||
6de1352f5f | |||
c55977d5e4 | |||
ad986c1efe | |||
ca2ff3481e | |||
effe9210fc | |||
e49a358b22 | |||
a2bf0315ac | |||
2caa3c3d1a | |||
92307b187d | |||
e0757600b6 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
node_modules/
|
||||
nginxconfig/zones/
|
||||
nginxconfig/
|
||||
coverage/
|
||||
docs/
|
||||
docs/
|
||||
.nogit/
|
@ -1,35 +1,29 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
before_script:
|
||||
- "apt-get update && apt-get install nginx -y"
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm install
|
||||
- npmci npm test stable
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
environment: npmjs-com_registry
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci npm prepare
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Lossless GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
26
README.md
26
README.md
@ -1,20 +1,30 @@
|
||||
# smartnginx
|
||||
|
||||
control nginx from node, TypeScript ready
|
||||
|
||||
## Status
|
||||
|
||||
[](https://gitlab.com/pushrocks/smartnginx/commits/master)
|
||||
|
||||
## Features
|
||||
|
||||
- easy reverse configuration
|
||||
- automatic letsencrypt DNS01 challenge based ssl cert generation
|
||||
- automatic nginx process handling zero-downtime config reloading
|
||||
- works in Docker environements
|
||||
|
||||
## Usage
|
||||
|
||||
We recommend the use of TypeScript! :)
|
||||
|
||||
```typescript
|
||||
import * as smartnginx from "smartnginx";
|
||||
myNginxConfig = new smartnginx.NginxConfig();
|
||||
myNginxZone = new smartnginx.NginxZone({
|
||||
zoneName:"some.example.com",
|
||||
type:"reverseProxy",
|
||||
destination:"192.192.192.192" // some destination IP
|
||||
import * as smartnginx from 'smartnginx';
|
||||
const smartnginxInstance = new smartnginx.SmartNginx();
|
||||
myNginxHost = new smartnginx.NginxHost({
|
||||
hostName: 'some.example.com',
|
||||
type: 'reverseProxy',
|
||||
destination: '192.192.192.192' // some destination IP
|
||||
});
|
||||
myNginxConfig.addZone(myNginxZone); // adds the zone to the config
|
||||
myNginxConfig.deploy(); // deploys the referenced NginxConfig and restarts nginx
|
||||
```
|
||||
myNginxConfig.deploy(); // deploys the referenced NginxConfig and gracefully reloads it
|
||||
```
|
||||
|
7
dist/index.d.ts
vendored
7
dist/index.d.ts
vendored
@ -1,4 +1,3 @@
|
||||
import * as CommandModule from "./smartnginx.command";
|
||||
export { NginxConfig } from "./smartnginx.classes.nginxconfig";
|
||||
export { NginxZone, zoneTypes } from "./smartnginx.classes.nginxzone";
|
||||
export declare let command: typeof CommandModule;
|
||||
export * from "./smartnginx.classes.nginxconfig";
|
||||
export * from "./smartnginx.classes.nginxprocess";
|
||||
export * from "./smartnginx.classes.nginxhost";
|
||||
|
16
dist/index.js
vendored
16
dist/index.js
vendored
@ -1,11 +1,9 @@
|
||||
"use strict";
|
||||
var CommandModule = require("./smartnginx.command");
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
// classes
|
||||
var smartnginx_classes_nginxconfig_1 = require("./smartnginx.classes.nginxconfig");
|
||||
exports.NginxConfig = smartnginx_classes_nginxconfig_1.NginxConfig;
|
||||
var smartnginx_classes_nginxzone_1 = require("./smartnginx.classes.nginxzone");
|
||||
exports.NginxZone = smartnginx_classes_nginxzone_1.NginxZone;
|
||||
exports.zoneTypes = smartnginx_classes_nginxzone_1.zoneTypes;
|
||||
// exports
|
||||
exports.command = CommandModule;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQ0EsSUFBWSxhQUFhLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUV0RCxVQUFVO0FBQ1YsK0NBQTBCLGtDQUFrQyxDQUFDO0FBQXJELG1FQUFxRDtBQUM3RCw2Q0FBa0MsZ0NBQWdDLENBQUM7QUFBM0QsNkRBQVM7QUFBQyw2REFBaUQ7QUFFbkUsVUFBVTtBQUNDLGVBQU8sR0FBRyxhQUFhLENBQUMifQ==
|
||||
__export(require("./smartnginx.classes.nginxconfig"));
|
||||
__export(require("./smartnginx.classes.nginxprocess"));
|
||||
__export(require("./smartnginx.classes.nginxhost"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsVUFBVTtBQUNWLGlCQUFjLGtDQUFrQyxDQUFDLEVBQUE7QUFDakQsaUJBQWMsbUNBQW1DLENBQUMsRUFBQTtBQUNsRCxpQkFBYyxnQ0FBZ0MsQ0FBQyxFQUFBIn0=
|
23
dist/smartnginx.classes.nginxconfig.d.ts
vendored
23
dist/smartnginx.classes.nginxconfig.d.ts
vendored
@ -1,10 +1,19 @@
|
||||
import { NginxZone } from "./smartnginx.classes.nginxzone";
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import { NginxHost } from "./smartnginx.classes.nginxhost";
|
||||
import { NginxProcess } from "./smartnginx.classes.nginxprocess";
|
||||
/**
|
||||
* main class that manages a NginxInstance
|
||||
*/
|
||||
export declare class NginxConfig {
|
||||
zones: NginxZone[];
|
||||
hosts: NginxHost[];
|
||||
cert: plugins.cert.Cert;
|
||||
nginxProcess: NginxProcess;
|
||||
isDeployed: boolean;
|
||||
constructor();
|
||||
addZone(zoneArg: NginxZone): void;
|
||||
listZones(): NginxZone[];
|
||||
removeZones(zoneArg: NginxZone): void;
|
||||
deploy(nginxRestartArg?: boolean): void;
|
||||
constructor(optionsArg: plugins.cert.ICertConstructorOptions);
|
||||
addHost(nginxHostArg: NginxHost): void;
|
||||
listHosts(): NginxHost[];
|
||||
removeHost(nginxHostArg: NginxHost): void;
|
||||
clean(): void;
|
||||
deploy(): plugins.q.Promise<{}>;
|
||||
}
|
||||
|
92
dist/smartnginx.classes.nginxconfig.js
vendored
92
dist/smartnginx.classes.nginxconfig.js
vendored
@ -1,51 +1,71 @@
|
||||
"use strict";
|
||||
var plugins = require("./smartnginx.plugins");
|
||||
var paths = require("./smartnginx.paths");
|
||||
var command = require("./smartnginx.command");
|
||||
var snippets = require("./smartnginx.snippets");
|
||||
var allConfigs = [];
|
||||
var NginxConfig = (function () {
|
||||
function NginxConfig() {
|
||||
this.zones = [];
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
const paths = require("./smartnginx.paths");
|
||||
const snippets = require("./smartnginx.snippets");
|
||||
const smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
|
||||
let allConfigs = [];
|
||||
/**
|
||||
* main class that manages a NginxInstance
|
||||
*/
|
||||
class NginxConfig {
|
||||
constructor(optionsArg) {
|
||||
this.hosts = [];
|
||||
this.nginxProcess = new smartnginx_classes_nginxprocess_1.NginxProcess(this);
|
||||
this.isDeployed = false;
|
||||
this.cert = new plugins.cert.Cert({
|
||||
cfEmail: optionsArg.cfEmail,
|
||||
cfKey: optionsArg.cfKey,
|
||||
sslDir: paths.nginxCertBase,
|
||||
gitOriginRepo: optionsArg.gitOriginRepo,
|
||||
testMode: optionsArg.testMode
|
||||
});
|
||||
}
|
||||
;
|
||||
// interact with Zones
|
||||
NginxConfig.prototype.addZone = function (zoneArg) {
|
||||
this.zones.push(zoneArg);
|
||||
};
|
||||
NginxConfig.prototype.listZones = function () {
|
||||
return this.zones;
|
||||
};
|
||||
// interact with Hosts
|
||||
addHost(nginxHostArg) {
|
||||
this.hosts.push(nginxHostArg);
|
||||
}
|
||||
listHosts() {
|
||||
return this.hosts;
|
||||
}
|
||||
;
|
||||
NginxConfig.prototype.removeZones = function (zoneArg) {
|
||||
};
|
||||
// handle deployment of zones
|
||||
NginxConfig.prototype.deploy = function (nginxRestartArg) {
|
||||
if (nginxRestartArg === void 0) { nginxRestartArg = false; }
|
||||
plugins.smartfile.fs.removeSync(paths.nginxConfigBase);
|
||||
removeHost(nginxHostArg) {
|
||||
}
|
||||
clean() {
|
||||
this.hosts = [];
|
||||
}
|
||||
// handle deployment of hosts
|
||||
deploy() {
|
||||
let done = plugins.q.defer();
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
|
||||
for (var _i = 0, allConfigs_1 = allConfigs; _i < allConfigs_1.length; _i++) {
|
||||
var config = allConfigs_1[_i];
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxHostFileBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
|
||||
for (let config of allConfigs) {
|
||||
config.isDeployed = false;
|
||||
}
|
||||
;
|
||||
this.isDeployed = true;
|
||||
for (var _a = 0, _b = this.zones; _a < _b.length; _a++) {
|
||||
var zone = _b[_a];
|
||||
zone.deploy();
|
||||
// write base config
|
||||
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
|
||||
// deploy hosts
|
||||
let promiseArray = [];
|
||||
for (let host of this.hosts) {
|
||||
let hostDeployedPromise = host.deploy(this.cert);
|
||||
hostDeployedPromise.then(() => {
|
||||
plugins.beautylog.info(`Host ${host.hostName} deployed!`);
|
||||
this.nginxProcess.reloadConfig();
|
||||
});
|
||||
promiseArray.push(hostDeployedPromise);
|
||||
}
|
||||
;
|
||||
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), plugins.path.join(paths.nginxConfigBase, "nginx.conf"));
|
||||
if (nginxRestartArg) {
|
||||
command.restart(this);
|
||||
}
|
||||
;
|
||||
};
|
||||
plugins.q.all(promiseArray)
|
||||
.then(() => {
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
return NginxConfig;
|
||||
}());
|
||||
}
|
||||
exports.NginxConfig = NginxConfig;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELElBQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsSUFBWSxPQUFPLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUNoRC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BSSxDQUFDLG1CQUFtQixDQUFDLENBQUM7UUFDM0MsQ0FBQztRQUFBLENBQUM7UUFDRixPQUFPLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUM7YUFDdEIsSUFBSSxDQUFDO1lBQ0YsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ25CLENBQUMsQ0FBQyxDQUFDO1FBRVAsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFDTCxDQUFDO0FBNURZLG1CQUFXLGNBNER2QixDQUFBO0FBQUEsQ0FBQyJ9
|
25
dist/smartnginx.classes.nginxhost.d.ts
vendored
Normal file
25
dist/smartnginx.classes.nginxhost.d.ts
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
/**
|
||||
* the host config data that NginxHost needs to create a valid instance
|
||||
*/
|
||||
export interface IHostConfigData {
|
||||
hostName: string;
|
||||
type: hostTypes;
|
||||
destination: string;
|
||||
}
|
||||
export declare enum hostTypes {
|
||||
reverseProxy = 0,
|
||||
static = 1,
|
||||
}
|
||||
/**
|
||||
* manages a single nginx host
|
||||
*/
|
||||
export declare class NginxHost {
|
||||
hostName: string;
|
||||
type: hostTypes;
|
||||
destination: string;
|
||||
configString: string;
|
||||
constructor(optionsArg: IHostConfigData);
|
||||
deploy(certInstanceArg: plugins.cert.Cert): plugins.q.Promise<{}>;
|
||||
}
|
35
dist/smartnginx.classes.nginxhost.js
vendored
Normal file
35
dist/smartnginx.classes.nginxhost.js
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
const paths = require("./smartnginx.paths");
|
||||
const snippets = require("./smartnginx.snippets");
|
||||
(function (hostTypes) {
|
||||
hostTypes[hostTypes["reverseProxy"] = 0] = "reverseProxy";
|
||||
hostTypes[hostTypes["static"] = 1] = "static";
|
||||
})(exports.hostTypes || (exports.hostTypes = {}));
|
||||
var hostTypes = exports.hostTypes;
|
||||
/**
|
||||
* manages a single nginx host
|
||||
*/
|
||||
class NginxHost {
|
||||
constructor(optionsArg) {
|
||||
this.hostName = optionsArg.hostName;
|
||||
this.type = optionsArg.type;
|
||||
this.destination = optionsArg.destination;
|
||||
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
|
||||
}
|
||||
;
|
||||
deploy(certInstanceArg) {
|
||||
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;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.NginxHost = NginxHost;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54aG9zdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguY2xhc3Nlcy5uZ2lueGhvc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDaEQsTUFBWSxLQUFLLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUM1QyxNQUFZLFFBQVEsV0FBTSx1QkFLMUIsQ0FBQyxDQUxnRDtBQVdqRCxXQUFZLFNBQVM7SUFDakIseURBQVksQ0FBQTtJQUNaLDZDQUFNLENBQUE7QUFDVixDQUFDLEVBSFcsaUJBQVMsS0FBVCxpQkFBUyxRQUdwQjtBQUhELElBQVksU0FBUyxHQUFULGlCQUdYLENBQUE7QUFFRDs7R0FFRztBQUNIO0lBS0ksWUFBWSxVQUEwQjtRQUNsQ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" />
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
|
||||
/**
|
||||
* manages a nginxprocess for an NginxConfig
|
||||
*/
|
||||
export declare class NginxProcess {
|
||||
started: boolean;
|
||||
nginxConfig: NginxConfig;
|
||||
nginxChildProcess: plugins.childProcess.ChildProcess;
|
||||
constructor(nginxConfigArg: any);
|
||||
/**
|
||||
* start nginx
|
||||
*/
|
||||
start(): plugins.q.Promise<{}>;
|
||||
/**
|
||||
* reload config
|
||||
*/
|
||||
reloadConfig(): plugins.q.Promise<{}>;
|
||||
/**
|
||||
* stop the nginx instance
|
||||
*/
|
||||
stop(): plugins.q.Promise<{}>;
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
check(): boolean;
|
||||
}
|
79
dist/smartnginx.classes.nginxprocess.js
vendored
Normal file
79
dist/smartnginx.classes.nginxprocess.js
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
const paths = require("./smartnginx.paths");
|
||||
/**
|
||||
* manages a nginxprocess for an NginxConfig
|
||||
*/
|
||||
class NginxProcess {
|
||||
constructor(nginxConfigArg) {
|
||||
this.started = false;
|
||||
this.nginxConfig = nginxConfigArg;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* start nginx
|
||||
*/
|
||||
start() {
|
||||
let done = plugins.q.defer();
|
||||
if (typeof this.nginxChildProcess == "undefined") {
|
||||
this.nginxChildProcess = plugins.childProcess.exec(`nginx -c ${paths.nginxConfFile}`, function (error, stdout, stderr) {
|
||||
console.log(`stdout: ${stdout}`);
|
||||
console.log(`stderr: ${stderr}`);
|
||||
if (error !== null) {
|
||||
console.log(`exec error: ${error}`);
|
||||
}
|
||||
;
|
||||
});
|
||||
}
|
||||
;
|
||||
this.started = true;
|
||||
plugins.beautylog.info("started Nginx!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* reload config
|
||||
*/
|
||||
reloadConfig() {
|
||||
let done = plugins.q.defer();
|
||||
if (this.started == false) {
|
||||
this.start();
|
||||
}
|
||||
else {
|
||||
plugins.shelljs.exec("nginx -s reload");
|
||||
}
|
||||
;
|
||||
plugins.beautylog.ok("NginxProcess has loaded the new config!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* stop the nginx instance
|
||||
*/
|
||||
stop() {
|
||||
let done = plugins.q.defer();
|
||||
if (typeof this.nginxChildProcess != "undefined") {
|
||||
plugins.shelljs.exec("nginx -s quit");
|
||||
this.started = false;
|
||||
plugins.beautylog.info("stopped Nginx!");
|
||||
}
|
||||
else {
|
||||
plugins.beautylog.log("nginx already stopped!");
|
||||
}
|
||||
;
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
check() {
|
||||
return;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.NginxProcess = NginxProcess;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54cHJvY2Vzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguY2xhc3Nlcy5uZ2lueHByb2Nlc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDaEQsTUFBWSxLQUFLLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUk1Qzs7R0FFRztBQUNIO0lBSUksWUFBWSxjQUFjO1FBSDFCLFlBQU8sR0FBWSxLQUFLLENBQUM7UUFJckIsSUFBSSxDQUFDLFdBQVcsR0FBRyxjQUFjLENBQUM7SUFDdEMsQ0FBQzs7SUFFRDs7T0FFRztJQU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ILEtBQUs7UUFDRCxNQUFNLENBQUM7SUFDWCxDQUFDOztBQUNMLENBQUM7QUFqRVksb0JBQVksZUFpRXhCLENBQUEifQ==
|
16
dist/smartnginx.classes.nginxzone.d.ts
vendored
16
dist/smartnginx.classes.nginxzone.d.ts
vendored
@ -1,16 +0,0 @@
|
||||
export declare enum zoneTypes {
|
||||
reverseProxy = 0,
|
||||
static = 1,
|
||||
}
|
||||
export declare class NginxZone {
|
||||
zoneName: string;
|
||||
type: zoneTypes;
|
||||
destination: string;
|
||||
configString: string;
|
||||
constructor(optionsArg: {
|
||||
zoneName: string;
|
||||
type: zoneTypes;
|
||||
destination: string;
|
||||
});
|
||||
deploy(): void;
|
||||
}
|
27
dist/smartnginx.classes.nginxzone.js
vendored
27
dist/smartnginx.classes.nginxzone.js
vendored
@ -1,27 +0,0 @@
|
||||
"use strict";
|
||||
var plugins = require("./smartnginx.plugins");
|
||||
var paths = require("./smartnginx.paths");
|
||||
var snippets = require("./smartnginx.snippets");
|
||||
(function (zoneTypes) {
|
||||
zoneTypes[zoneTypes["reverseProxy"] = 0] = "reverseProxy";
|
||||
zoneTypes[zoneTypes["static"] = 1] = "static";
|
||||
})(exports.zoneTypes || (exports.zoneTypes = {}));
|
||||
var zoneTypes = exports.zoneTypes;
|
||||
var NginxZone = (function () {
|
||||
function NginxZone(optionsArg) {
|
||||
this.zoneName = optionsArg.zoneName;
|
||||
this.type = optionsArg.type;
|
||||
this.destination = optionsArg.destination;
|
||||
this.configString = snippets.getZoneConfigString(optionsArg.zoneName, optionsArg.destination);
|
||||
}
|
||||
;
|
||||
NginxZone.prototype.deploy = function () {
|
||||
var filePath = plugins.path.join(paths.nginxZoneBase, this.zoneName + ".conf");
|
||||
plugins.smartfile.memory.toFsSync(this.configString, filePath);
|
||||
};
|
||||
;
|
||||
return NginxZone;
|
||||
}());
|
||||
exports.NginxZone = NginxZone;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaW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UFRLENBQUMsSUFBSSxDQUFDLFlBQVksRUFBQyxRQUFRLENBQUMsQ0FBQztJQUNsRSxDQUFDOztJQUNMLGdCQUFDO0FBQUQsQ0FBQyxBQW5CRCxJQW1CQztBQW5CWSxpQkFBUyxZQW1CckIsQ0FBQTtBQUFBLENBQUMifQ==
|
19
dist/smartnginx.command.d.ts
vendored
19
dist/smartnginx.command.d.ts
vendored
@ -1,19 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
|
||||
/**
|
||||
* starts nginx
|
||||
*/
|
||||
export declare let start: (configArg: NginxConfig) => plugins.q.Promise<{}>;
|
||||
/**
|
||||
* restarts nginx
|
||||
*/
|
||||
export declare let restart: (configArg: NginxConfig) => plugins.q.Promise<{}>;
|
||||
/**
|
||||
* stops nginx
|
||||
*/
|
||||
export declare let stop: () => plugins.q.Promise<{}>;
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
export declare let check: () => boolean;
|
53
dist/smartnginx.command.js
vendored
53
dist/smartnginx.command.js
vendored
@ -1,53 +0,0 @@
|
||||
"use strict";
|
||||
var plugins = require("./smartnginx.plugins");
|
||||
var nginxChildProcess = undefined; // points to the nginx child process
|
||||
/**
|
||||
* starts nginx
|
||||
*/
|
||||
exports.start = function (configArg) {
|
||||
var done = plugins.q.defer();
|
||||
if (typeof nginxChildProcess == "undefined") {
|
||||
nginxChildProcess = plugins.childProcess.exec("nginx", function (error, stdout, stderr) {
|
||||
console.log("stdout: " + stdout);
|
||||
console.log("stderr: " + stderr);
|
||||
if (error !== null) {
|
||||
console.log("exec error: " + error);
|
||||
}
|
||||
});
|
||||
}
|
||||
;
|
||||
plugins.beautylog.info("started Nginx!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
/**
|
||||
* restarts nginx
|
||||
*/
|
||||
exports.restart = function (configArg) {
|
||||
return exports.stop().then(function () {
|
||||
return exports.start(configArg);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* stops nginx
|
||||
*/
|
||||
exports.stop = function () {
|
||||
var done = plugins.q.defer();
|
||||
if (typeof nginxChildProcess != "undefined") {
|
||||
nginxChildProcess.kill();
|
||||
plugins.beautylog.info("stopped Nginx!");
|
||||
}
|
||||
else {
|
||||
plugins.beautylog.log("nginx already stopped!");
|
||||
}
|
||||
;
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
exports.check = function () {
|
||||
return;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jb21tYW5kLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jb21tYW5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBS2hELElBQUksaUJBQWlCLEdBQUcsU0FBUyxDQUFDLENBQUMsb0NBQW9DO0FBR3ZFOztHQUVHO0FBQ1EsYUFBSyxHQUFHLFVBQUMsU0FBcUI7SUFDckMsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixFQUFFLENBQUEsQ0FBQyxPQUFPLGlCQUFpQixJQUFJLFdBQVcsQ0FBQyxDQUFBLENBQUM7UUFDeEMsaUJBQWlCLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFDLFVBQVMsS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNO1lBQ2hGLE9BQU8sQ0FBQyxHQUFHLENBQUMsYUFBVyxNQUFRLENBQUMsQ0FBQztZQUNqQyxPQUFPLENBQUMsR0FBRyxDQUFDLGFBQVcsTUFBUSxDQUFDLENBQ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PQUFPLEVBQUUsQ0FBQztJQUNmLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQztBQUVGOztHQUVHO0FBQ1EsYUFBSyxHQUFHO0lBQ2YsTUFBTSxDQUFDO0FBQ1gsQ0FBQyxDQUFDIn0=
|
4
dist/smartnginx.paths.d.ts
vendored
4
dist/smartnginx.paths.d.ts
vendored
@ -1,3 +1,5 @@
|
||||
export declare let packageBase: string;
|
||||
export declare let nginxConfigBase: string;
|
||||
export declare let nginxZoneBase: string;
|
||||
export declare let nginxHostFileBase: string;
|
||||
export declare let nginxCertBase: string;
|
||||
export declare let nginxConfFile: string;
|
||||
|
12
dist/smartnginx.paths.js
vendored
12
dist/smartnginx.paths.js
vendored
@ -1,6 +1,10 @@
|
||||
"use strict";
|
||||
var plugins = require("./smartnginx.plugins");
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
// directories
|
||||
exports.packageBase = plugins.path.join(__dirname, "../");
|
||||
exports.nginxConfigBase = plugins.path.join(exports.packageBase, "nginxconfig/");
|
||||
exports.nginxZoneBase = plugins.path.join(exports.nginxConfigBase, "zones");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQVksT0FBTyxXQUFNLHNCQUV6QixDQUFDLENBRjhDO0FBRXBDLG1CQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFDO0FBQ2pELHVCQUFlLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsbUJBQVcsRUFBQyxjQUFjLENBQUMsQ0FBQztBQUNoRSxxQkFBYSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHVCQUFlLEVBQUMsT0FBTyxDQUFDLENBQUMifQ==
|
||||
exports.nginxConfigBase = plugins.path.join(exports.packageBase, "nginxconfig");
|
||||
exports.nginxHostFileBase = plugins.path.join(exports.nginxConfigBase, "hosts");
|
||||
exports.nginxCertBase = plugins.path.join(exports.nginxConfigBase, "cert");
|
||||
// files
|
||||
exports.nginxConfFile = plugins.path.join(exports.nginxConfigBase, "nginx.conf");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUd6QixDQUFDLENBSDhDO0FBRS9DLGNBQWM7QUFDSCxtQkFBVyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxLQUFLLENBQUMsQ0FBQztBQUNqRCx1QkFBZSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLG1CQUFXLEVBQUMsYUFBYSxDQUFDLENBQUM7QUFDL0QseUJBQWlCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsdUJBQWUsRUFBQyxPQUFPLENBQUMsQ0FBQztBQUMvRCxxQkFBYSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHVCQUFlLEVBQUMsTUFBTSxDQUFDLENBQUM7QUFFckUsUUFBUTtBQUNHLHFCQUFhLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsdUJBQWUsRUFBQyxZQUFZLENBQUMsQ0FBQyJ9
|
2
dist/smartnginx.plugins.d.ts
vendored
2
dist/smartnginx.plugins.d.ts
vendored
@ -4,6 +4,6 @@ export import cert = require("cert");
|
||||
export import childProcess = require("child_process");
|
||||
export import path = require("path");
|
||||
export import q = require("q");
|
||||
export declare let shelljs: any;
|
||||
export import shelljs = require("shelljs");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartstring = require("smartstring");
|
||||
|
2
dist/smartnginx.plugins.js
vendored
2
dist/smartnginx.plugins.js
vendored
@ -8,4 +8,4 @@ exports.q = require("q");
|
||||
exports.shelljs = require("shelljs");
|
||||
exports.smartfile = require("smartfile");
|
||||
exports.smartstring = require("smartstring");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixvQkFBWSxXQUFXLGVBQWUsQ0FBQyxDQUFDO0FBQ3hDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDcEIsZUFBTyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQztBQUMxQixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLG1CQUFXLFdBQVcsYUFBYSxDQUFDLENBQUMifQ==
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixvQkFBWSxXQUFXLGVBQWUsQ0FBQyxDQUFDO0FBQ3hDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9
|
2
dist/smartnginx.snippets.d.ts
vendored
2
dist/smartnginx.snippets.d.ts
vendored
@ -1,2 +1,2 @@
|
||||
export declare let getBaseConfigString: () => string;
|
||||
export declare let getZoneConfigString: (zoneNameArg: string, destinationIpArg: string) => string;
|
||||
export declare let getHostConfigString: (hostNameArg: string, destinationIpArg: string) => string;
|
||||
|
106
dist/smartnginx.snippets.js
vendored
106
dist/smartnginx.snippets.js
vendored
@ -1,11 +1,103 @@
|
||||
"use strict";
|
||||
var plugins = require("./smartnginx.plugins");
|
||||
exports.getBaseConfigString = function () {
|
||||
var baseConfig = plugins.smartstring.indent.normalize("\n\t\tuser www-data;\n\t\tworker_processes auto;\n\t\tpid /run/nginx.pid;\n\n\t\tevents {\n\t\t\tworker_connections 768;\n\t\t\t# multi_accept on;\n\t\t}\n\n\t\thttp {\n\t\t\tserver_names_hash_bucket_size 128;\n\n\t\t\t##\n\t\t\t# Basic Settings\n\t\t\t##\n\n\t\t\tsendfile on;\n\t\t\ttcp_nopush on;\n\t\t\ttcp_nodelay on;\n\t\t\tkeepalive_timeout 65;\n\t\t\ttypes_hash_max_size 2048;\n\t\t\t# server_tokens off;\n\n\t\t\t# server_names_hash_bucket_size 64;\n\t\t\t# server_name_in_redirect off;\n\n\t\t\tinclude /etc/nginx/mime.types;\n\t\t\tdefault_type application/octet-stream;\n\n\t\t\t##\n\t\t\t# SSL Settings\n\t\t\t##\n\n\t\t\tssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE\n\t\t\tssl_prefer_server_ciphers on;\n\n\t\t\t##\n\t\t\t# Logging Settings\n\t\t\t##\n\n\t\t\taccess_log /var/log/nginx/access.log;\n\t\t\terror_log /var/log/nginx/error.log;\n\n\t\t\t##\n\t\t\t# Gzip Settings\n\t\t\t##\n\n\t\t\tgzip on;\n\t\t\tgzip_disable \"msie6\";\n\n\t\t\t# gzip_vary on;\n\t\t\t# gzip_proxied any;\n\t\t\t# gzip_comp_level 6;\n\t\t\t# gzip_buffers 16 8k;\n\t\t\t# gzip_http_version 1.1;\n\t\t\t# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;\n\n\t\t\t##\n\t\t\t# Virtual Host Configs\n\t\t\t##\n\n\t\t\tinclude /etc/nginx/conf.d/*.conf;\n\t\t\tinclude /etc/nginx/sites-enabled/*;\n\t\t}\n\t\tdaemon off;\n\t");
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
const paths = require("./smartnginx.paths");
|
||||
exports.getBaseConfigString = () => {
|
||||
let baseConfig = plugins.smartstring.indent.normalize(`
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
# multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
server_names_hash_bucket_size 128;
|
||||
|
||||
##
|
||||
# Basic Settings
|
||||
##
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
# server_tokens off;
|
||||
|
||||
# server_names_hash_bucket_size 64;
|
||||
# server_name_in_redirect off;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
##
|
||||
# SSL Settings
|
||||
##
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
##
|
||||
# Logging Settings
|
||||
##
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
##
|
||||
# Gzip Settings
|
||||
##
|
||||
|
||||
gzip on;
|
||||
gzip_disable "msie6";
|
||||
|
||||
# gzip_vary on;
|
||||
# gzip_proxied any;
|
||||
# gzip_comp_level 6;
|
||||
# gzip_buffers 16 8k;
|
||||
# gzip_http_version 1.1;
|
||||
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
##
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include ${paths.nginxHostFileBase}/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
daemon off;
|
||||
`);
|
||||
return baseConfig;
|
||||
};
|
||||
exports.getZoneConfigString = function (zoneNameArg, destinationIpArg) {
|
||||
var zoneConfig = plugins.smartstring.indent.normalize("\n\t\tupstream " + zoneNameArg + " {\n\t\t\tserver " + destinationIpArg + ";\n\t\t}\n\n\t\tserver {\n\t\t\tlisten *:80 ;\n\t\t\tserver_name " + zoneNameArg + ";\n\t\t\trewrite ^ https://" + zoneNameArg + "$request_uri? permanent;\n\t\t}\n\n\t\tserver {\n\t\t\tlisten *:443 ssl;\n\t\t\tserver_name " + zoneNameArg + ";\n\t\t\tssl_certificate /LE_CERTS/" + zoneNameArg + "/fullchain.pem;\n\t\t\tssl_certificate_key /LE_CERTS/" + zoneNameArg + "/privkey.pem;\n\n\t\t\tlocation / {\n\t\t\t\tproxy_pass http://" + zoneNameArg + ";\n\t\t\t\tinclude /etc/nginx/proxy_params;\n\t\t\t}\n\t\t\tlocation ~ /.git {\n\t\t\t\tdeny all;\n\t\t\t}\n\t\t}\n\t");
|
||||
return zoneConfig;
|
||||
exports.getHostConfigString = (hostNameArg, destinationIpArg) => {
|
||||
let hostConfig = plugins.smartstring.indent.normalize(`
|
||||
upstream ${hostNameArg} {
|
||||
server ${destinationIpArg};
|
||||
}
|
||||
|
||||
server {
|
||||
listen *:80 ;
|
||||
server_name ${hostNameArg};
|
||||
rewrite ^ https://${hostNameArg}$request_uri? permanent;
|
||||
}
|
||||
|
||||
server {
|
||||
listen *:443 ssl;
|
||||
server_name ${hostNameArg};
|
||||
ssl_certificate ${paths.nginxCertBase}/${hostNameArg}/fullchain.pem;
|
||||
ssl_certificate_key ${paths.nginxCertBase}/${hostNameArg}/privkey.pem;
|
||||
|
||||
location / {
|
||||
proxy_pass http://${hostNameArg};
|
||||
include /etc/nginx/proxy_params;
|
||||
}
|
||||
location ~ /\.git {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
`);
|
||||
return hostConfig;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5zbmlwcGV0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguc25pcHBldHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDckMsMkJBQW1CLEdBQUc7SUFDaEMsSUFBSSxVQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDLDY0Q0FrRXJELENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDbkIsQ0FBQyxDQUFBO0FBR1UsMkJBQW1CLEdBQUcsVUFBQyxXQUFrQixFQUFDLGdCQUF1QjtJQUMzRSxJQUFJLFVBQVUsR0FBRyxPQUFPLENBQUMsV0F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s4QkFDRSxXQUFXOzs7OztpQkFLeEIsV0FBVztxQkFDUCxLQUFLLENBQUMsYUFBYSxJQUFJLFdBQVc7eUJBQzlCLEtBQUssQ0FBQyxhQUFhLElBQUksV0FBVzs7O3dCQUduQyxXQUFXOzs7Ozs7O0VBT2pDLENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDbkIsQ0FBQyxDQUFDIn0=
|
@ -1,65 +0,0 @@
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
# multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
server_names_hash_bucket_size 128;
|
||||
|
||||
##
|
||||
# Basic Settings
|
||||
##
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
# server_tokens off;
|
||||
|
||||
# server_names_hash_bucket_size 64;
|
||||
# server_name_in_redirect off;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
##
|
||||
# SSL Settings
|
||||
##
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
##
|
||||
# Logging Settings
|
||||
##
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
##
|
||||
# Gzip Settings
|
||||
##
|
||||
|
||||
gzip on;
|
||||
gzip_disable "msie6";
|
||||
|
||||
# gzip_vary on;
|
||||
# gzip_proxied any;
|
||||
# gzip_comp_level 6;
|
||||
# gzip_buffers 16 8k;
|
||||
# gzip_http_version 1.1;
|
||||
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
##
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
daemon off;
|
8
npmextra.json
Normal file
8
npmextra.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"npmdocker": {
|
||||
|
||||
}
|
||||
}
|
1603
package-lock.json
generated
Normal file
1603
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@ -1,12 +1,14 @@
|
||||
{
|
||||
"name": "smartnginx",
|
||||
"version": "0.0.6",
|
||||
"name": "@pushrocks/smartnginx",
|
||||
"version": "2.0.19",
|
||||
"private": false,
|
||||
"description": "control nginx from node, TypeScript ready",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)",
|
||||
"cleanTest": "(rm -r nginxconfig)"
|
||||
"test": "tstest test/",
|
||||
"cleanTest": "(rm -r nginxconfig) && npm run test",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -22,17 +24,20 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
|
||||
"dependencies": {
|
||||
"@types/q": "*",
|
||||
"beautylog": "^5.0.13",
|
||||
"cert": "0.0.13",
|
||||
"q": "^1.4.1",
|
||||
"shelljs": "^0.7.0",
|
||||
"smartfile": "^4.0.10",
|
||||
"smartstring": "^2.0.14"
|
||||
"@pushrocks/lik": "^3.0.4",
|
||||
"@pushrocks/smartfile": "^6.0.11",
|
||||
"@pushrocks/smartlog": "^2.0.11",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smartshell": "^2.0.13",
|
||||
"@pushrocks/smartstring": "^3.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts-g": "^5.2.6",
|
||||
"should": "^9.0.2",
|
||||
"typings-test": "^1.0.1"
|
||||
"@gitzone/tsbuild": "^2.1.4",
|
||||
"@gitzone/tsrun": "^1.1.17",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@pushrocks/qenv": "^4.0.0",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"tslint": "^5.12.1",
|
||||
"tslint-config-prettier": "^1.17.0"
|
||||
}
|
||||
}
|
||||
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import "typings-test";
|
||||
import "should";
|
37
test/test.js
37
test/test.js
@ -1,37 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
require("should");
|
||||
var smartnginx = require("../dist/index");
|
||||
describe("smartnginx", function () {
|
||||
var testNginxConfig;
|
||||
var testNginxZone01;
|
||||
var testNginxZone02;
|
||||
describe("NginxZone", function () {
|
||||
it("\"new NginxZone()\" should produce an instance of NginxConfig", function () {
|
||||
testNginxZone01 = new smartnginx.NginxZone({
|
||||
zoneName: "test1.bleu.de",
|
||||
type: smartnginx.zoneTypes.reverseProxy,
|
||||
destination: "192.192.192.192"
|
||||
});
|
||||
testNginxZone01.should.be.instanceof(smartnginx.NginxZone);
|
||||
console.log(testNginxZone01.configString);
|
||||
});
|
||||
});
|
||||
describe("NginxConfig", function () {
|
||||
it("\"new NginxConfig()\" should produce an instance of NginxConfig", function () {
|
||||
testNginxConfig = new smartnginx.NginxConfig();
|
||||
testNginxConfig.should.be.instanceof(smartnginx.NginxConfig);
|
||||
});
|
||||
describe(".addZone()", function () {
|
||||
it("should add a zone to NginxConfig Object", function () {
|
||||
testNginxConfig.addZone(testNginxZone01);
|
||||
});
|
||||
});
|
||||
describe(".deploy()", function () {
|
||||
it("should deploy a config from an instance", function () {
|
||||
testNginxConfig.deploy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY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gsUUFBUSxDQUFDLFlBQVksRUFBQztZQUNsQixFQUFFLENBQUMseUNBQXlDLEVBQUM7Z0JBQ3pDLGVBQWUsQ0FBQyxPQUFPLENBQUMsZUFBZSxDQUFDLENBQUM7WUFDN0MsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQztRQUNILFFBQVEsQ0FBQyxXQUFXLEVBQUM7WUFDakIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDO2dCQUN6QyxlQUFlLENBQUMsTUFBTSxFQUFFLENBQUM7WUFDN0IsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFDLENBQUMifQ==
|
85
test/test.ts
85
test/test.ts
@ -1,36 +1,53 @@
|
||||
import "typings-test";
|
||||
import "should";
|
||||
import * as smartnginx from "../dist/index";
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import path = require('path');
|
||||
|
||||
describe("smartnginx",function(){
|
||||
let testNginxConfig:smartnginx.NginxConfig;
|
||||
let testNginxZone01:smartnginx.NginxZone;
|
||||
let testNginxZone02:smartnginx.NginxZone;
|
||||
describe("NginxZone",function(){
|
||||
it(`"new NginxZone()" should produce an instance of NginxConfig`,function(){
|
||||
testNginxZone01 = new smartnginx.NginxZone({
|
||||
zoneName:"test1.bleu.de",
|
||||
type:smartnginx.zoneTypes.reverseProxy,
|
||||
destination:"192.192.192.192"
|
||||
});
|
||||
testNginxZone01.should.be.instanceof(smartnginx.NginxZone);
|
||||
console.log(testNginxZone01.configString);
|
||||
});
|
||||
});
|
||||
describe("NginxConfig",function(){
|
||||
it(`"new NginxConfig()" should produce an instance of NginxConfig`,function(){
|
||||
testNginxConfig = new smartnginx.NginxConfig();
|
||||
testNginxConfig.should.be.instanceof(smartnginx.NginxConfig);
|
||||
});
|
||||
describe(".addZone()",function(){
|
||||
it("should add a zone to NginxConfig Object",function(){
|
||||
testNginxConfig.addZone(testNginxZone01);
|
||||
})
|
||||
});
|
||||
describe(".deploy()",function(){
|
||||
it("should deploy a config from an instance",function(){
|
||||
testNginxConfig.deploy();
|
||||
})
|
||||
});
|
||||
});
|
||||
import { Qenv } from '@pushrocks/qenv';
|
||||
const testQenv = new Qenv('./', './.nogit/');
|
||||
|
||||
import * as smartnginx from '../ts/index';
|
||||
|
||||
let testSmartNginx: smartnginx.SmartNginx;
|
||||
let testNginxZone01: smartnginx.NginxHost;
|
||||
let testNginxZone02: smartnginx.NginxHost;
|
||||
|
||||
tap.test('should create a valid instance of SmartNginx', async () => {
|
||||
testSmartNginx = new smartnginx.SmartNginx({});
|
||||
expect(testSmartNginx).to.be.instanceof(smartnginx.SmartNginx);
|
||||
});
|
||||
|
||||
tap.test(`should produce an instance of NginxConfig`, async () => {
|
||||
testNginxZone01 = new smartnginx.NginxHost(testSmartNginx, {
|
||||
hostName: 'test100.bleu.de',
|
||||
destination: '192.192.192.191',
|
||||
privateKey: 'some private',
|
||||
publicKey: 'some public'
|
||||
});
|
||||
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
|
||||
hostName: 'test102.bleu.de',
|
||||
destination: '192.192.192.192',
|
||||
privateKey: 'some private',
|
||||
publicKey: 'some public'
|
||||
});
|
||||
expect(testNginxZone01).to.be.instanceof(smartnginx.NginxHost);
|
||||
});
|
||||
|
||||
tap.test('.addHostCandidate() should add a zone to NginxConfig Object', async () => {
|
||||
testSmartNginx.addHostCandidate(testNginxZone01);
|
||||
testSmartNginx.addHostCandidate(testNginxZone02);
|
||||
});
|
||||
|
||||
tap.test('.deploy() should deploy a config from an instance', async () => {
|
||||
await testSmartNginx.deploy();
|
||||
});
|
||||
|
||||
tap.test('should not redeploy', async () => {
|
||||
testSmartNginx.addHostCandidate(testNginxZone01);
|
||||
testSmartNginx.addHostCandidate(testNginxZone02);
|
||||
await testSmartNginx.deploy();
|
||||
});
|
||||
|
||||
tap.test('.stop() should end the process', async () => {
|
||||
testSmartNginx.nginxProcess.stop();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
11
ts/index.ts
11
ts/index.ts
@ -1,9 +1,6 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as CommandModule from "./smartnginx.command";
|
||||
import * as plugins from './smartnginx.plugins';
|
||||
|
||||
// classes
|
||||
export {NginxConfig} from "./smartnginx.classes.nginxconfig";
|
||||
export {NginxZone,zoneTypes} from "./smartnginx.classes.nginxzone";
|
||||
|
||||
// exports
|
||||
export let command = CommandModule;
|
||||
export * from './smartnginx.classes.smartnginx';
|
||||
export * from './smartnginx.classes.nginxprocess';
|
||||
export * from './smartnginx.classes.nginxhost';
|
||||
|
6
ts/interfaces/hostconfig.ts
Normal file
6
ts/interfaces/hostconfig.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export interface IHostConfig {
|
||||
hostName: string;
|
||||
destination: string;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
}
|
0
ts/interfaces/index.ts
Normal file
0
ts/interfaces/index.ts
Normal file
@ -1,46 +0,0 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as paths from "./smartnginx.paths";
|
||||
import * as command from "./smartnginx.command";
|
||||
import * as snippets from "./smartnginx.snippets"
|
||||
import {NginxZone} from "./smartnginx.classes.nginxzone";
|
||||
let allConfigs:NginxConfig[] = [];
|
||||
|
||||
export class NginxConfig {
|
||||
zones:NginxZone[] = [];
|
||||
isDeployed:boolean = false;
|
||||
constructor(){
|
||||
|
||||
};
|
||||
|
||||
// interact with Zones
|
||||
addZone(zoneArg:NginxZone){
|
||||
this.zones.push(zoneArg);
|
||||
}
|
||||
listZones():NginxZone[] {
|
||||
return this.zones;
|
||||
};
|
||||
removeZones(zoneArg:NginxZone){
|
||||
|
||||
}
|
||||
|
||||
// handle deployment of zones
|
||||
deploy(nginxRestartArg:boolean = false){
|
||||
plugins.smartfile.fs.removeSync(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
|
||||
for(let config of allConfigs){
|
||||
config.isDeployed = false;
|
||||
};
|
||||
this.isDeployed = true;
|
||||
for(let zone of this.zones){
|
||||
zone.deploy();
|
||||
};
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
snippets.getBaseConfigString(),
|
||||
plugins.path.join(paths.nginxConfigBase,"nginx.conf")
|
||||
);
|
||||
if(nginxRestartArg){
|
||||
command.restart(this);
|
||||
};
|
||||
};
|
||||
};
|
53
ts/smartnginx.classes.nginxhost.ts
Normal file
53
ts/smartnginx.classes.nginxhost.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import * as plugins from './smartnginx.plugins';
|
||||
import * as paths from './smartnginx.paths';
|
||||
import * as snippets from './smartnginx.snippets';
|
||||
|
||||
import { SmartNginx } from './smartnginx.classes.smartnginx';
|
||||
|
||||
import { IHostConfig } from './interfaces/hostconfig';
|
||||
|
||||
export enum hostTypes {
|
||||
reverseProxy
|
||||
}
|
||||
|
||||
/**
|
||||
* manages a single nginx host
|
||||
*/
|
||||
export class NginxHost implements IHostConfig {
|
||||
/**
|
||||
* smartnginxInstance this NginHost belongs to
|
||||
*/
|
||||
public smartnginxInstance: SmartNginx;
|
||||
|
||||
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;
|
||||
|
||||
constructor(smartnginxInstanceArg: SmartNginx, optionsArg: IHostConfig) {
|
||||
this.smartnginxInstance = smartnginxInstanceArg;
|
||||
this.hostName = optionsArg.hostName;
|
||||
this.destination = optionsArg.destination;
|
||||
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
|
||||
this.privateKey = optionsArg.privateKey;
|
||||
this.publicKey = optionsArg.publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param certInstanceArg
|
||||
*/
|
||||
public async deploy() {
|
||||
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`);
|
||||
// writeConfig
|
||||
plugins.smartfile.memory.toFsSync(this.configString, filePathConfig);
|
||||
|
||||
// write ssl
|
||||
plugins.smartfile.memory.toFsSync(this.privateKey, filePathPrivate);
|
||||
plugins.smartfile.memory.toFsSync(this.publicKey, filePathPublic);
|
||||
|
||||
}
|
||||
}
|
69
ts/smartnginx.classes.nginxprocess.ts
Normal file
69
ts/smartnginx.classes.nginxprocess.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import * as plugins from './smartnginx.plugins';
|
||||
import * as paths from './smartnginx.paths';
|
||||
import { SmartNginx } from './smartnginx.classes.smartnginx';
|
||||
import { NginxHost } from './smartnginx.classes.nginxhost';
|
||||
|
||||
import { Smartshell } from '@pushrocks/smartshell';
|
||||
|
||||
import { ChildProcess } from 'child_process';
|
||||
|
||||
/**
|
||||
* manages a nginxprocess for an NginxConfig
|
||||
*/
|
||||
export class NginxProcess {
|
||||
public started: boolean = false;
|
||||
public smartNginxRef: SmartNginx;
|
||||
private nginxChildProcess: ChildProcess;
|
||||
private smartshellInstance = new Smartshell({
|
||||
executor: 'bash'
|
||||
});
|
||||
|
||||
constructor(nginxRefArg: SmartNginx) {
|
||||
this.smartNginxRef = nginxRefArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* start nginx
|
||||
*/
|
||||
public async start() {
|
||||
if (!this.nginxChildProcess) {
|
||||
this.nginxChildProcess = (await this.smartshellInstance.execStreaming(
|
||||
`nginx -c ${paths.nginxConfFile}`
|
||||
)).childProcess;
|
||||
}
|
||||
this.started = true;
|
||||
plugins.smartlog.defaultLogger.log('info', 'started Nginx!');
|
||||
}
|
||||
|
||||
/**
|
||||
* reload config
|
||||
*/
|
||||
public async reloadConfig() {
|
||||
if (!this.started) {
|
||||
this.start();
|
||||
} else {
|
||||
await this.smartshellInstance.exec('nginx -s reload');
|
||||
}
|
||||
this.smartNginxRef.logger.log('info', 'NginxProcess has loaded the new config!');
|
||||
}
|
||||
|
||||
/**
|
||||
* stop the nginx instance
|
||||
*/
|
||||
public async stop() {
|
||||
if (this.nginxChildProcess) {
|
||||
this.smartshellInstance.exec('nginx -s quit');
|
||||
this.started = false;
|
||||
this.smartNginxRef.logger.log('info', 'stopped Nginx!');
|
||||
} else {
|
||||
this.smartNginxRef.logger.log('info', 'nginx already stopped!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
public check(): boolean {
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as paths from "./smartnginx.paths";
|
||||
import * as command from "./smartnginx.command";
|
||||
import * as snippets from "./smartnginx.snippets"
|
||||
export enum zoneTypes {
|
||||
reverseProxy,
|
||||
static
|
||||
}
|
||||
|
||||
export class NginxZone {
|
||||
zoneName:string; // the zone name e.g. domain name
|
||||
type:zoneTypes;
|
||||
destination:string;
|
||||
configString:string; // the actual zone config file as string
|
||||
constructor(optionsArg:{
|
||||
zoneName:string,
|
||||
type:zoneTypes,
|
||||
destination:string
|
||||
}){
|
||||
this.zoneName = optionsArg.zoneName;
|
||||
this.type = optionsArg.type;
|
||||
this.destination = optionsArg.destination;
|
||||
this.configString = snippets.getZoneConfigString(optionsArg.zoneName,optionsArg.destination);
|
||||
};
|
||||
deploy(){
|
||||
let filePath = plugins.path.join(paths.nginxZoneBase,this.zoneName + ".conf");
|
||||
plugins.smartfile.memory.toFsSync(this.configString,filePath);
|
||||
};
|
||||
};
|
124
ts/smartnginx.classes.smartnginx.ts
Normal file
124
ts/smartnginx.classes.smartnginx.ts
Normal file
@ -0,0 +1,124 @@
|
||||
import * as plugins from './smartnginx.plugins';
|
||||
import * as paths from './smartnginx.paths';
|
||||
import * as snippets from './smartnginx.snippets';
|
||||
import { NginxHost } from './smartnginx.classes.nginxhost';
|
||||
import { NginxProcess } from './smartnginx.classes.nginxprocess';
|
||||
import { IHostConfig } from './interfaces/hostconfig';
|
||||
|
||||
/**
|
||||
* main class that manages a NginxInstance
|
||||
*/
|
||||
export class SmartNginx {
|
||||
public logger: plugins.smartlog.Smartlog;
|
||||
|
||||
// the objectmaps
|
||||
private deployedHosts = new plugins.lik.Objectmap<NginxHost>();
|
||||
private hostCandidates = new plugins.lik.Objectmap<NginxHost>();
|
||||
|
||||
public nginxProcess: NginxProcess = new NginxProcess(this);
|
||||
constructor(optionsArg: { logger?: plugins.smartlog.Smartlog }) {
|
||||
optionsArg.logger
|
||||
? (this.logger = optionsArg.logger)
|
||||
: (this.logger = plugins.smartlog.defaultLogger);
|
||||
}
|
||||
|
||||
// ===================
|
||||
// interact with Hosts
|
||||
// ===================
|
||||
|
||||
/**
|
||||
* add a host
|
||||
* @param nginxHostArg
|
||||
*/
|
||||
public addHostCandidate(optionsArg: IHostConfig): NginxHost {
|
||||
const nginxHost = new NginxHost(this, optionsArg);
|
||||
this.hostCandidates.add(nginxHost);
|
||||
return nginxHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a NginxHost by hostname
|
||||
* @param hostNameArg
|
||||
*/
|
||||
public getDeployedNginxHostByHostName(hostNameArg: string): NginxHost {
|
||||
return this.deployedHosts.find(nginxHost => {
|
||||
return nginxHost.hostName === hostNameArg;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* listHosts
|
||||
*/
|
||||
public async listDeployedHosts(): Promise<NginxHost[]> {
|
||||
return this.deployedHosts.getArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a Host
|
||||
* @param nginxHostArg
|
||||
*/
|
||||
public async removeDeployedHost(nginxHostArg: NginxHost) {
|
||||
if (this.hostCandidates.isEmpty()) {
|
||||
this.deployedHosts.forEach(hostArg => {
|
||||
this.hostCandidates.add(hostArg);
|
||||
});
|
||||
}
|
||||
this.hostCandidates.remove(nginxHostArg);
|
||||
this.deploy();
|
||||
}
|
||||
|
||||
/**
|
||||
* check wether there has been a diverging host configuration
|
||||
* this function will only redeploy the nginx configuration in case there has been a change
|
||||
*/
|
||||
private async areHostsDiverged(): Promise<boolean> {
|
||||
let hostCounter = 0;
|
||||
let unfoundHosts = 0;
|
||||
await this.hostCandidates.forEach(async hostCandidateArg => {
|
||||
let foundHost = false;
|
||||
await this.deployedHosts.forEach(async deployedHostArg => {
|
||||
if (
|
||||
hostCandidateArg.hostName === deployedHostArg.hostName &&
|
||||
hostCandidateArg.destination === deployedHostArg.destination
|
||||
) {
|
||||
hostCounter++;
|
||||
foundHost = true;
|
||||
}
|
||||
});
|
||||
if (!foundHost) {
|
||||
unfoundHosts++;
|
||||
}
|
||||
});
|
||||
return (
|
||||
this.deployedHosts.getArray().length !== this.hostCandidates.getArray().length ||
|
||||
hostCounter !== this.deployedHosts.getArray().length ||
|
||||
unfoundHosts !== 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* deploy the current stack and restart nginx
|
||||
*/
|
||||
public async deploy() {
|
||||
if (await this.areHostsDiverged()) {
|
||||
this.logger.log('ok', `hosts have diverged, trigger config deployment and nginx reload!`);
|
||||
this.deployedHosts.wipe();
|
||||
this.deployedHosts.addArray(this.hostCandidates.getArray());
|
||||
this.hostCandidates.wipe();
|
||||
|
||||
// write base config
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigDirPath);
|
||||
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
|
||||
|
||||
// deploy hosts
|
||||
plugins.smartfile.fs.ensureEmptyDirSync(paths.nginxHostDirPath);
|
||||
for (const host of this.deployedHosts.getArray()) {
|
||||
await host.deploy();
|
||||
this.logger.log('info', `Host ${host.hostName} deployed!`);
|
||||
}
|
||||
this.nginxProcess.reloadConfig();
|
||||
} else {
|
||||
this.logger.log('info', `hosts have not diverged, skipping nginx reload`);
|
||||
this.hostCandidates.wipe();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import {NginxConfig} from "./smartnginx.classes.nginxconfig";
|
||||
import {NginxZone} from "./smartnginx.classes.nginxzone";
|
||||
|
||||
|
||||
let nginxChildProcess = undefined; // points to the nginx child process
|
||||
|
||||
|
||||
/**
|
||||
* starts nginx
|
||||
*/
|
||||
export let start = (configArg:NginxConfig) => {
|
||||
let done = plugins.q.defer();
|
||||
if(typeof nginxChildProcess == "undefined"){
|
||||
nginxChildProcess = plugins.childProcess.exec("nginx",function(error, stdout, stderr){
|
||||
console.log(`stdout: ${stdout}`);
|
||||
console.log(`stderr: ${stderr}`);
|
||||
if (error !== null) {
|
||||
console.log(`exec error: ${error}`);
|
||||
}
|
||||
});
|
||||
};
|
||||
plugins.beautylog.info("started Nginx!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* restarts nginx
|
||||
*/
|
||||
export let restart = (configArg:NginxConfig) => {
|
||||
return stop().then(
|
||||
() => {
|
||||
return start(configArg);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* stops nginx
|
||||
*/
|
||||
export let stop = () => {
|
||||
let done = plugins.q.defer();
|
||||
if(typeof nginxChildProcess != "undefined"){
|
||||
nginxChildProcess.kill();
|
||||
plugins.beautylog.info("stopped Nginx!");
|
||||
} else {
|
||||
plugins.beautylog.log("nginx already stopped!");
|
||||
};
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
export let check = ():boolean => {
|
||||
return;
|
||||
};
|
@ -1,5 +1,9 @@
|
||||
import * as plugins from "./smartnginx.plugins"
|
||||
import * as plugins from './smartnginx.plugins';
|
||||
|
||||
export let packageBase = plugins.path.join(__dirname,"../");
|
||||
export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig/");
|
||||
export let nginxZoneBase = plugins.path.join(nginxConfigBase,"zones");
|
||||
// directories
|
||||
export const packageBase = plugins.path.join(__dirname, '../');
|
||||
export const nginxConfigDirPath = plugins.path.join(packageBase, 'nginxconfig');
|
||||
export const nginxHostDirPath = plugins.path.join(nginxConfigDirPath, 'hosts');
|
||||
|
||||
// files
|
||||
export const nginxConfFile = plugins.path.join(nginxConfigDirPath, 'nginx.conf');
|
@ -1,9 +1,14 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import cert = require("cert");
|
||||
export import childProcess = require("child_process");
|
||||
export import path = require("path");
|
||||
export import q = require("q");
|
||||
export let shelljs = require("shelljs");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartstring = require("smartstring");
|
||||
// native
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartshell from '@pushrocks/smartshell';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
|
||||
export { lik, smartlog, smartpromise, smartshell, smartfile, smartstring };
|
||||
|
@ -1,9 +1,10 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as plugins from './smartnginx.plugins';
|
||||
import * as paths from './smartnginx.paths';
|
||||
export let getBaseConfigString = () => {
|
||||
let baseConfig = plugins.smartstring.indent.normalize(`
|
||||
let baseConfig = plugins.smartstring.indent.normalize(`
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
pid /run/nginx/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
@ -62,42 +63,42 @@ export let getBaseConfigString = () => {
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
include ${paths.nginxHostDirPath}/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
daemon off;
|
||||
`);
|
||||
return baseConfig;
|
||||
}
|
||||
return baseConfig;
|
||||
};
|
||||
|
||||
|
||||
export let getZoneConfigString = (zoneNameArg:string,destinationIpArg:string) => {
|
||||
let zoneConfig = plugins.smartstring.indent.normalize(`
|
||||
upstream ${zoneNameArg} {
|
||||
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) => {
|
||||
let hostConfig = plugins.smartstring.indent.normalize(`
|
||||
upstream ${hostNameArg} {
|
||||
server ${destinationIpArg};
|
||||
}
|
||||
|
||||
server {
|
||||
listen *:80 ;
|
||||
server_name ${zoneNameArg};
|
||||
rewrite ^ https://${zoneNameArg}$request_uri? permanent;
|
||||
server_name ${hostNameArg};
|
||||
rewrite ^ https://${hostNameArg}$request_uri? permanent;
|
||||
}
|
||||
|
||||
server {
|
||||
listen *:443 ssl;
|
||||
server_name ${zoneNameArg};
|
||||
ssl_certificate /LE_CERTS/${zoneNameArg}/fullchain.pem;
|
||||
ssl_certificate_key /LE_CERTS/${zoneNameArg}/privkey.pem;
|
||||
server_name ${hostNameArg};
|
||||
ssl_certificate ${paths.nginxHostDirPath}/${hostNameArg}.public.pem;
|
||||
ssl_certificate_key ${paths.nginxHostDirPath}/${hostNameArg}.private.pem;
|
||||
|
||||
location / {
|
||||
proxy_pass http://${zoneNameArg};
|
||||
include /etc/nginx/proxy_params;
|
||||
}
|
||||
location ~ /\.git {
|
||||
deny all;
|
||||
proxy_http_version 1.1;
|
||||
keepalive 100;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_pass http://${hostNameArg};
|
||||
}
|
||||
}
|
||||
`);
|
||||
return zoneConfig;
|
||||
return hostConfig;
|
||||
};
|
||||
|
||||
|
17
tslint.json
Normal file
17
tslint.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user