Compare commits
56 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
244b21ca36 | |||
87eb7084c0 | |||
e77b3d0355 | |||
871ff06040 | |||
1f2105f75e | |||
43e8549042 | |||
9864dcc56a | |||
bd6c76cbfd | |||
c50f1f73dd | |||
a15f05cedb | |||
8ebde757b2 | |||
48a1429332 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
nginxconfig/zones/
|
nginxconfig/
|
||||||
coverage/
|
coverage/
|
||||||
docs/
|
docs/
|
||||||
|
.nogit/
|
@ -1,35 +1,29 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
|
|
||||||
testLEGACY:
|
before_script:
|
||||||
stage: test
|
- "apt-get update && apt-get install nginx -y"
|
||||||
script:
|
|
||||||
- npmci test legacy
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test lts
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci npm install
|
||||||
|
- npmci npm test stable
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
|
environment: npmjs-com_registry
|
||||||
script:
|
script:
|
||||||
- npmci publish
|
- npmci npm prepare
|
||||||
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
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.
|
30
README.md
30
README.md
@ -1,2 +1,30 @@
|
|||||||
# smartnginx
|
# smartnginx
|
||||||
control nginx from node
|
|
||||||
|
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';
|
||||||
|
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 gracefully reloads it
|
||||||
|
```
|
||||||
|
4
dist/index.d.ts
vendored
4
dist/index.d.ts
vendored
@ -1 +1,3 @@
|
|||||||
export { NginxConfig, NginxZone } from "./smartnginx.classes.nginxconfig";
|
export * from "./smartnginx.classes.nginxconfig";
|
||||||
|
export * from "./smartnginx.classes.nginxprocess";
|
||||||
|
export * from "./smartnginx.classes.nginxhost";
|
||||||
|
11
dist/index.js
vendored
11
dist/index.js
vendored
@ -1,6 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
function __export(m) {
|
||||||
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||||
|
}
|
||||||
// classes
|
// classes
|
||||||
var smartnginx_classes_nginxconfig_1 = require("./smartnginx.classes.nginxconfig");
|
__export(require("./smartnginx.classes.nginxconfig"));
|
||||||
exports.NginxConfig = smartnginx_classes_nginxconfig_1.NginxConfig;
|
__export(require("./smartnginx.classes.nginxprocess"));
|
||||||
exports.NginxZone = smartnginx_classes_nginxconfig_1.NginxZone;
|
__export(require("./smartnginx.classes.nginxhost"));
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBRUEsVUFBVTtBQUNWLCtDQUFvQyxrQ0FBa0MsQ0FBQztBQUEvRCxtRUFBVztBQUFDLCtEQUFtRCJ9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsVUFBVTtBQUNWLGlCQUFjLGtDQUFrQyxDQUFDLEVBQUE7QUFDakQsaUJBQWMsbUNBQW1DLENBQUMsRUFBQTtBQUNsRCxpQkFBYyxnQ0FBZ0MsQ0FBQyxFQUFBIn0=
|
35
dist/smartnginx.classes.nginxconfig.d.ts
vendored
35
dist/smartnginx.classes.nginxconfig.d.ts
vendored
@ -1,20 +1,19 @@
|
|||||||
export declare enum ZoneTypes {
|
/// <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 {
|
export declare class NginxConfig {
|
||||||
zones: NginxZone[];
|
hosts: NginxHost[];
|
||||||
constructor();
|
cert: plugins.cert.Cert;
|
||||||
addZone(zoneArg: NginxZone): void;
|
nginxProcess: NginxProcess;
|
||||||
listZones(): NginxZone[];
|
isDeployed: boolean;
|
||||||
removeZones(zoneArg: NginxZone): void;
|
constructor(optionsArg: plugins.cert.ICertConstructorOptions);
|
||||||
deploy(): void;
|
addHost(nginxHostArg: NginxHost): void;
|
||||||
nginxStart(): void;
|
listHosts(): NginxHost[];
|
||||||
nginxStop(): void;
|
removeHost(nginxHostArg: NginxHost): void;
|
||||||
}
|
clean(): void;
|
||||||
export declare class NginxZone {
|
deploy(): plugins.q.Promise<{}>;
|
||||||
domain: any;
|
|
||||||
constructor(optionsArg: {
|
|
||||||
zoneName: string;
|
|
||||||
type: ZoneTypes;
|
|
||||||
destination: string;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
96
dist/smartnginx.classes.nginxconfig.js
vendored
96
dist/smartnginx.classes.nginxconfig.js
vendored
@ -1,39 +1,71 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
(function (ZoneTypes) {
|
const plugins = require("./smartnginx.plugins");
|
||||||
})(exports.ZoneTypes || (exports.ZoneTypes = {}));
|
const paths = require("./smartnginx.paths");
|
||||||
var ZoneTypes = exports.ZoneTypes;
|
const snippets = require("./smartnginx.snippets");
|
||||||
var NginxConfig = (function () {
|
const smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
|
||||||
function NginxConfig() {
|
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
|
// interact with Hosts
|
||||||
NginxConfig.prototype.addZone = function (zoneArg) {
|
addHost(nginxHostArg) {
|
||||||
};
|
this.hosts.push(nginxHostArg);
|
||||||
NginxConfig.prototype.listZones = function () {
|
}
|
||||||
return this.zones;
|
listHosts() {
|
||||||
};
|
return this.hosts;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
NginxConfig.prototype.removeZones = function (zoneArg) {
|
removeHost(nginxHostArg) {
|
||||||
};
|
}
|
||||||
// handle deployment of zones
|
clean() {
|
||||||
NginxConfig.prototype.deploy = function () {
|
this.hosts = [];
|
||||||
};
|
}
|
||||||
|
// handle deployment of hosts
|
||||||
|
deploy() {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nginxHostFileBase);
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
|
||||||
|
for (let config of allConfigs) {
|
||||||
|
config.isDeployed = false;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
this.isDeployed = true;
|
||||||
|
// 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.q.all(promiseArray)
|
||||||
|
.then(() => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
NginxConfig.prototype.nginxStart = function () {
|
}
|
||||||
};
|
|
||||||
;
|
|
||||||
NginxConfig.prototype.nginxStop = function () {
|
|
||||||
};
|
|
||||||
;
|
|
||||||
return NginxConfig;
|
|
||||||
}());
|
|
||||||
exports.NginxConfig = NginxConfig;
|
exports.NginxConfig = NginxConfig;
|
||||||
;
|
;
|
||||||
var NginxZone = (function () {
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELE1BQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsTUFBWSxRQUFRLFdBQU0sdUJBQXVCLENBQUMsQ0FBQTtBQUVsRCxrREFBNkIsbUNBQW1DLENBQUMsQ0FBQTtBQUNqRSxJQUFJLFVBQVUsR0FBa0IsRUFBRSxDQUFDO0FBRW5DOztHQUVHO0FBQ0g7SUFLSSxZQUFZLFVBQWdEO1FBSjVELFVBQUssR0FBZ0IsRUFBRSxDQUFDO1FBRXhCLGlCQUFZLEdBQWlCLElBQUksOENBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUNwRCxlQUFVLEdBQVksS0FBSyxDQUFDO1FBRXhCLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FB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ER2QixDQUFBO0FBQUEsQ0FBQyJ9
|
||||||
function NginxZone(optionsArg) {
|
|
||||||
}
|
|
||||||
return NginxZone;
|
|
||||||
}());
|
|
||||||
exports.NginxZone = NginxZone;
|
|
||||||
var mynginx = new NginxConfig();
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQSxXQUFZLFNBQVM7QUFFckIsQ0FBQyxFQUZXLGlCQUFTLEtBQVQsaUJBQVMsUUFFcEI7QUFGRCxJQUFZLFNBQVMsR0FBVCxpQkFFWCxDQUFBO0FBRUQ7SUFFSTtJQUVBLENBQUM7O0lBRUQsc0JBQXNCO0lBQ3RCLDZCQUFPLEdBQVAsVUFBUSxPQUFpQjtJQUV6QixDQUFDO0lBQ0QsK0JBQVMsR0FBVDtRQUNJLE1BQU0sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDO0lBQ3RCLENBQUM7O0lBQ0QsaUNBQVcsR0FBWCxVQUFZLE9BQWlCO0lBRTdCLENBQUM7SUFFRCw2QkFBNkI7SUFDN0IsNEJBQU0sR0FBTjtJQUVBLENBQUM7O0lBQ0QsZ0NBQVUsR0FBVjtJQUVBLENBQUM7O0lBQ0QsK0JBQVMsR0FBVDtJQUVBLENBQUM7O0lBQ0wsa0JBQUM7QUFBRCxDQUFDLEFBM0JELElBMkJDO0FBM0JZLG1CQUFXLGNBMkJ2QixDQUFBO0FBQUEsQ0FBQztBQUVGO0lBRUksbUJBQVksVUFJWDtJQUVELENBQUM7SUFDTCxnQkFBQztBQUFELENBQUMsQUFURCxJQVNDO0FBVFksaUJBQVMsWUFTckIsQ0FBQTtBQUVELElBQUksT0FBTyxHQUFHLElBQUksV0FBVyxFQUFFLENBQUMifQ==
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54aG9zdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguY2xhc3Nlcy5uZ2lueGhvc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDaEQsTUFBWSxLQUFLLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUM1QyxNQUFZLFFBQVEsV0FBTSx1QkFLMUIsQ0FBQyxDQUxnRDtBQVdqRCxXQUFZLFNBQVM7SUFDakIseURBQVksQ0FBQTtJQUNaLDZDQUFNLENBQUE7QUFDVixDQUFDLEVBSFcsaUJBQVMsS0FBVCxpQkFBUyxRQUdwQjtBQUhELElBQVksU0FBUyxHQUFULGlCQUdYLENBQUE7QUFFRDs7R0FFRztBQUNIO0lBS0ksWUFBWSxVQUEwQjtRQUNsQyxJQUFJLENBQUMsUUFBUSxHQUFHLFVBQVUsQ0FBQyxRQUFRLENBQUM7UUFDcEMsSUFBSSxDQUFDLElBQUksR0FBRyxVQUFVLENBQUMsSUFBSSxDQUFDO1FBQzVCLElBQUksQ0FBQyxXQUFXLEdBQUcsVUFBVSxDQUFDLFdBQVcsQ0FBQztRQUMxQyxJQUFJLENBQUMsWUFBWSxHQUFHLFFBQVEsQ0FBQyxtQkFBbUIsQ0FBQyxVQUFVLENBQUMsUUFBUSxFQUFFLFVBQVUsQ0FBQyxXQUFXLENBQUMsQ0FBQztJQUNsRyxDQUFDOztJQUNELE1BQU0sQ0FBQyxlQUFrQztRQUNyQyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQzdCLElBQUksUUFBUSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxpQkFBaUIsRUFBRSxJQUFJLENBQUMsUUFBUSxHQUFHLE9BQU8sQ0FBQyxDQUFDO1FBQ25GLGNBQWM7UUFDZCxPQUFPLENBQUMsU0FBUyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsSUFBSSxDQUFDLFlBQVksRUFBRSxRQUFRLENBQUMsQ0FBQztRQUMvRCxXQUFXO1FBQ1gsZUFBZSxDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDO2FBQ3ZDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDeEIsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFDTCxDQUFDO0FBckJZLGlCQUFTLFlBcUJyQixDQUFBO0FBQUEsQ0FBQyJ9
|
29
dist/smartnginx.classes.nginxprocess.d.ts
vendored
Normal file
29
dist/smartnginx.classes.nginxprocess.d.ts
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/// <reference types="node" />
|
||||||
|
/// <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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54cHJvY2Vzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguY2xhc3Nlcy5uZ2lueHByb2Nlc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFz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M7WUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyx3QkFBd0IsQ0FBQyxDQUFDO1FBQ3BELENBQUM7UUFBQSxDQUFDO1FBQ0YsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ2YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7SUFFRDs7T0FFRztJQUNILEtBQUs7UUFDRCxNQUFNLENBQUM7SUFDWCxDQUFDOztBQUNMLENBQUM7QUFqRVksb0JBQVksZUFpRXhCLENBQUEifQ==
|
5
dist/smartnginx.paths.d.ts
vendored
Normal file
5
dist/smartnginx.paths.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export declare let packageBase: string;
|
||||||
|
export declare let nginxConfigBase: string;
|
||||||
|
export declare let nginxHostFileBase: string;
|
||||||
|
export declare let nginxCertBase: string;
|
||||||
|
export declare let nginxConfFile: string;
|
10
dist/smartnginx.paths.js
vendored
Normal file
10
dist/smartnginx.paths.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
const plugins = require("./smartnginx.plugins");
|
||||||
|
// directories
|
||||||
|
exports.packageBase = plugins.path.join(__dirname, "../");
|
||||||
|
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
|
6
dist/smartnginx.plugins.d.ts
vendored
6
dist/smartnginx.plugins.d.ts
vendored
@ -1,3 +1,9 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export import beautylog = require("beautylog");
|
||||||
export import cert = require("cert");
|
export import cert = require("cert");
|
||||||
|
export import childProcess = require("child_process");
|
||||||
|
export import path = require("path");
|
||||||
export import q = require("q");
|
export import q = require("q");
|
||||||
|
export import shelljs = require("shelljs");
|
||||||
export import smartfile = require("smartfile");
|
export import smartfile = require("smartfile");
|
||||||
|
export import smartstring = require("smartstring");
|
||||||
|
8
dist/smartnginx.plugins.js
vendored
8
dist/smartnginx.plugins.js
vendored
@ -1,5 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
exports.beautylog = require("beautylog");
|
||||||
exports.cert = require("cert");
|
exports.cert = require("cert");
|
||||||
|
exports.childProcess = require("child_process");
|
||||||
|
exports.path = require("path");
|
||||||
exports.q = require("q");
|
exports.q = require("q");
|
||||||
|
exports.shelljs = require("shelljs");
|
||||||
exports.smartfile = require("smartfile");
|
exports.smartfile = require("smartfile");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBYyxZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUMifQ==
|
exports.smartstring = require("smartstring");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixvQkFBWSxXQUFXLGVBQWUsQ0FBQyxDQUFDO0FBQ3hDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9
|
2
dist/smartnginx.snippets.d.ts
vendored
Normal file
2
dist/smartnginx.snippets.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export declare let getBaseConfigString: () => string;
|
||||||
|
export declare let getHostConfigString: (hostNameArg: string, destinationIpArg: string) => string;
|
103
dist/smartnginx.snippets.js
vendored
Normal file
103
dist/smartnginx.snippets.js
vendored
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
"use strict";
|
||||||
|
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.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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5zbmlwcGV0cy5qcyIsInNvdXJjZVJvb3QiOiIi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||||
|
|
||||||
|
}
|
||||||
|
}
|
1628
package-lock.json
generated
Normal file
1628
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@ -1,11 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "smartnginx",
|
"name": "@pushrocks/smartnginx",
|
||||||
"version": "0.0.1",
|
"version": "2.0.7",
|
||||||
"description": "control nginx from node",
|
"private": false,
|
||||||
|
"description": "control nginx from node, TypeScript ready",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "tstest test/",
|
||||||
|
"cleanTest": "(rm -r nginxconfig) && npm run test",
|
||||||
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -21,14 +24,17 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
|
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "0.0.25-alpha",
|
"@pushrocks/smartfile": "^6.0.11",
|
||||||
"cert": "0.0.13",
|
"@pushrocks/smartlog": "^2.0.9",
|
||||||
"q": "^1.4.1",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"smartfile": "^4.0.10"
|
"@pushrocks/smartshell": "^2.0.13",
|
||||||
|
"@pushrocks/smartstring": "^3.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts-g": "^5.2.6",
|
"@gitzone/tsbuild": "^2.1.4",
|
||||||
"should": "^9.0.2",
|
"@gitzone/tsrun": "^1.1.17",
|
||||||
"typings-test": "^1.0.1"
|
"@gitzone/tstest": "^1.0.18",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
|
"qenv": "^1.1.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import "typings-test";
|
|
||||||
import "should";
|
|
@ -1,4 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-test");
|
|
||||||
require("should");
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQSJ9
|
|
48
test/test.ts
48
test/test.ts
@ -1,3 +1,45 @@
|
|||||||
import "typings-test";
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import "should";
|
import path = require('path');
|
||||||
import smartnginx from "../dist/index"
|
|
||||||
|
import { Qenv } from 'qenv';
|
||||||
|
let testQenv = new Qenv(process.cwd(), path.join(process.cwd(), '.nogit'));
|
||||||
|
|
||||||
|
|
||||||
|
import * as smartnginx from '../ts';
|
||||||
|
|
||||||
|
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'
|
||||||
|
});
|
||||||
|
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
|
||||||
|
hostName: 'test102.bleu.de',
|
||||||
|
destination: '192.192.192.192'
|
||||||
|
});
|
||||||
|
expect(testNginxZone01).to.be.instanceof(smartnginx.NginxHost);
|
||||||
|
console.log(testNginxZone01.configString);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('.addZone() should add a zone to NginxConfig Object', async () => {
|
||||||
|
testSmartNginx.addHost('test200.bleu.de', '192.192.192.191');
|
||||||
|
testSmartNginx.addHost('test201.blue.de', '192.192.192.191');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('.deploy() should deploy a config from an instance', async () => {
|
||||||
|
await testSmartNginx.deploy();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('.stop() should end the process', async () => {
|
||||||
|
testSmartNginx.nginxProcess.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import * as plugins from "./smartnginx.plugins";
|
import * as plugins from './smartnginx.plugins';
|
||||||
|
|
||||||
// classes
|
// classes
|
||||||
export {NginxConfig,NginxZone} from "./smartnginx.classes.nginxconfig";
|
export * from './smartnginx.classes.smartnginx';
|
||||||
|
export * from './smartnginx.classes.nginxprocess';
|
||||||
|
export * from './smartnginx.classes.nginxhost';
|
||||||
|
15
ts/smartnginx.classes.certhandler.ts
Normal file
15
ts/smartnginx.classes.certhandler.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import * as plugins from './smartnginx.plugins';
|
||||||
|
|
||||||
|
export class CertHandler {
|
||||||
|
private _readyDeferred = plugins.smartpromise.defer();
|
||||||
|
certHandlerReady = this._readyDeferred.promise;
|
||||||
|
constructor() {} // nothing to do here for now
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ensure a cert is at the right location
|
||||||
|
* @param hostName
|
||||||
|
*/
|
||||||
|
async ensureCertForHost(hostName) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,47 +0,0 @@
|
|||||||
import * as plugins from "./smartnginx.plugins";
|
|
||||||
|
|
||||||
export enum ZoneTypes {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export class NginxConfig {
|
|
||||||
zones:NginxZone[];
|
|
||||||
constructor(){
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// interact with Zones
|
|
||||||
addZone(zoneArg:NginxZone){
|
|
||||||
|
|
||||||
}
|
|
||||||
listZones():NginxZone[] {
|
|
||||||
return this.zones;
|
|
||||||
};
|
|
||||||
removeZones(zoneArg:NginxZone){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle deployment of zones
|
|
||||||
deploy(){
|
|
||||||
|
|
||||||
};
|
|
||||||
nginxStart(){
|
|
||||||
|
|
||||||
};
|
|
||||||
nginxStop(){
|
|
||||||
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export class NginxZone {
|
|
||||||
domain
|
|
||||||
constructor(optionsArg:{
|
|
||||||
zoneName:string,
|
|
||||||
type:ZoneTypes,
|
|
||||||
destination:string
|
|
||||||
}){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mynginx = new NginxConfig();
|
|
47
ts/smartnginx.classes.nginxhost.ts
Normal file
47
ts/smartnginx.classes.nginxhost.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import * as plugins from './smartnginx.plugins';
|
||||||
|
import * as paths from './smartnginx.paths';
|
||||||
|
import * as snippets from './smartnginx.snippets';
|
||||||
|
|
||||||
|
import { SmartNginx } from './smartnginx.classes.smartnginx';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the host config data that NginxHost needs to create a valid instance
|
||||||
|
*/
|
||||||
|
export interface IHostConfigData {
|
||||||
|
hostName: string;
|
||||||
|
destination: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum hostTypes {
|
||||||
|
reverseProxy
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* manages a single nginx host
|
||||||
|
*/
|
||||||
|
export class NginxHost {
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
82
ts/smartnginx.classes.nginxprocess.ts
Normal file
82
ts/smartnginx.classes.nginxprocess.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* manages a nginxprocess for an NginxConfig
|
||||||
|
*/
|
||||||
|
export class NginxProcess {
|
||||||
|
started: boolean = false;
|
||||||
|
nginxConfig: SmartNginx;
|
||||||
|
nginxChildProcess: plugins.childProcess.ChildProcess;
|
||||||
|
smartshellInstance = new Smartshell({
|
||||||
|
executor: 'bash'
|
||||||
|
});
|
||||||
|
constructor(nginxConfigArg) {
|
||||||
|
this.nginxConfig = nginxConfigArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* start nginx
|
||||||
|
*/
|
||||||
|
start() {
|
||||||
|
let done = plugins.smartpromise.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.smartlog.defaultLogger.log('info', 'started Nginx!');
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reload config
|
||||||
|
*/
|
||||||
|
reloadConfig() {
|
||||||
|
let done = plugins.smartpromise.defer();
|
||||||
|
if (this.started == false) {
|
||||||
|
this.start();
|
||||||
|
} else {
|
||||||
|
this.smartshellInstance.exec('nginx -s reload');
|
||||||
|
}
|
||||||
|
plugins.smartlog.defaultLogger.log('info', 'NginxProcess has loaded the new config!');
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stop the nginx instance
|
||||||
|
*/
|
||||||
|
stop() {
|
||||||
|
let done = plugins.smartpromise.defer();
|
||||||
|
if (typeof this.nginxChildProcess != 'undefined') {
|
||||||
|
this.smartshellInstance.exec('nginx -s quit');
|
||||||
|
this.started = false;
|
||||||
|
plugins.smartlog.defaultLogger.log('info', 'stopped Nginx!');
|
||||||
|
} else {
|
||||||
|
plugins.smartlog.defaultLogger.log('info', 'nginx already stopped!');
|
||||||
|
}
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks if nginx is in path
|
||||||
|
*/
|
||||||
|
check(): boolean {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
86
ts/smartnginx.classes.smartnginx.ts
Normal file
86
ts/smartnginx.classes.smartnginx.ts
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
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 { CertHandler } from './smartnginx.classes.certhandler';
|
||||||
|
let allConfigs: SmartNginx[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main class that manages a NginxInstance
|
||||||
|
*/
|
||||||
|
export class SmartNginx {
|
||||||
|
certHandler = new CertHandler();
|
||||||
|
hosts: NginxHost[] = [];
|
||||||
|
nginxProcess: NginxProcess = new NginxProcess(this);
|
||||||
|
isDeployed: boolean = false;
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===================
|
||||||
|
// interact with Hosts
|
||||||
|
// ===================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add a host
|
||||||
|
* @param nginxHostArg
|
||||||
|
*/
|
||||||
|
addHost(hostNameArg: string, destinationIp: string): NginxHost {
|
||||||
|
const nginxHost = new NginxHost(this, {
|
||||||
|
hostName: hostNameArg,
|
||||||
|
destination: destinationIp
|
||||||
|
})
|
||||||
|
this.hosts.push(nginxHost);
|
||||||
|
return nginxHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
getNginxHostByHostName(hostNameArg: string): NginxHost {
|
||||||
|
return this.hosts.find(nginxHost => {
|
||||||
|
return nginxHost.hostName === hostNameArg;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* listHosts
|
||||||
|
*/
|
||||||
|
listHosts(): NginxHost[] {
|
||||||
|
return this.hosts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove a Host
|
||||||
|
* @param nginxHostArg
|
||||||
|
*/
|
||||||
|
removeHost(nginxHostArg: NginxHost) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean all hosts
|
||||||
|
*/
|
||||||
|
clean() {
|
||||||
|
this.hosts = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deploy the current stack and restart nginx
|
||||||
|
*/
|
||||||
|
async deploy() {
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nginxHostFileBase);
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
|
||||||
|
for (let config of allConfigs) {
|
||||||
|
config.isDeployed = false;
|
||||||
|
}
|
||||||
|
this.isDeployed = true;
|
||||||
|
// write base config
|
||||||
|
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
|
||||||
|
// deploy hosts
|
||||||
|
let promiseArray = [];
|
||||||
|
for (let host of this.hosts) {
|
||||||
|
await host.deploy();
|
||||||
|
plugins.smartlog.defaultLogger.log('info', `Host ${host.hostName} deployed!`);
|
||||||
|
this.nginxProcess.reloadConfig();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
11
ts/smartnginx.paths.ts
Normal file
11
ts/smartnginx.paths.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import * as plugins from './smartnginx.plugins';
|
||||||
|
|
||||||
|
// directories
|
||||||
|
export let packageBase = plugins.path.join(__dirname, '../');
|
||||||
|
export let nginxConfigBase = plugins.path.join(packageBase, 'nginxconfig');
|
||||||
|
|
||||||
|
export let nginxHostFileBase = plugins.path.join(nginxConfigBase, 'hosts');
|
||||||
|
export let nginxCertBase = plugins.path.join(nginxConfigBase, 'cert');
|
||||||
|
|
||||||
|
// files
|
||||||
|
export let nginxConfFile = plugins.path.join(nginxConfigBase, 'nginx.conf');
|
@ -1,3 +1,17 @@
|
|||||||
export import cert = require("cert");
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
export import q = require("q");
|
import * as childProcess from 'child_process';
|
||||||
export import smartfile = require("smartfile");
|
import * as path from 'path';
|
||||||
|
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 {
|
||||||
|
smartlog,
|
||||||
|
childProcess,
|
||||||
|
path,
|
||||||
|
smartpromise,
|
||||||
|
smartshell,
|
||||||
|
smartfile,
|
||||||
|
smartstring
|
||||||
|
}
|
102
ts/smartnginx.snippets.ts
Normal file
102
ts/smartnginx.snippets.ts
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
import * as plugins from './smartnginx.plugins';
|
||||||
|
import * as paths from './smartnginx.paths';
|
||||||
|
export let 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string) => {
|
||||||
|
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;
|
||||||
|
};
|
Reference in New Issue
Block a user