Compare commits

...

76 Commits

Author SHA1 Message Date
64bcce9e23 2.0.21 2019-01-19 03:04:38 +01:00
390812ec33 fix(core): update 2019-01-19 03:04:38 +01:00
a672bb920f 2.0.20 2019-01-19 02:46:41 +01:00
c3fabb6107 fix(core): update 2019-01-19 02:46:41 +01:00
b4ebdbae47 2.0.19 2019-01-19 02:44:52 +01:00
c55d2dcf10 fix(core): update 2019-01-19 02:44:52 +01:00
7274d5ea8a 2.0.18 2019-01-19 02:25:35 +01:00
1ec733c2a9 fix(core): update 2019-01-19 02:25:34 +01:00
3ef14d8ac7 2.0.17 2019-01-18 01:33:02 +01:00
f332bf95fe fix(core): update 2019-01-18 01:33:01 +01:00
6acad8a306 2.0.16 2019-01-18 00:46:09 +01:00
6ae672f707 fix(core): update 2019-01-18 00:46:08 +01:00
3d263e2181 2.0.15 2019-01-18 00:45:29 +01:00
85639f29af fix(core): update 2019-01-18 00:45:29 +01:00
85448a21fc 2.0.14 2019-01-17 13:39:16 +01:00
3b85c4a37e fix(core): update 2019-01-17 13:39:15 +01:00
67dd650dce 2.0.13 2019-01-17 02:50:32 +01:00
92eaf5f19a fix(core): update 2019-01-17 02:50:32 +01:00
fcf9a61b1d 2.0.12 2019-01-09 14:13:32 +01:00
fbd258a876 fix(core): update 2019-01-09 14:13:32 +01:00
c65b8fc1af 2.0.11 2019-01-09 14:10:57 +01:00
b7b588d713 fix(core): update 2019-01-09 14:10:57 +01:00
00d672c135 2.0.10 2019-01-09 12:18:56 +01:00
6a1e778b49 fix(core): update 2019-01-09 12:18:56 +01:00
4cfb26f62f 2.0.9 2019-01-09 12:18:07 +01:00
7ba3ad0b21 fix(core): update 2019-01-09 12:18:06 +01:00
cd93ec2560 2.0.8 2019-01-09 12:15:29 +01:00
ede884930e fix(core): update 2019-01-09 12:15:28 +01:00
1049920efd 2.0.7 2019-01-01 22:35:18 +01:00
b7a34403c5 fix(core): update 2019-01-01 22:35:18 +01:00
987e19372a 2.0.6 2019-01-01 22:34:37 +01:00
0b97aaee91 fix(core): update 2019-01-01 22:34:36 +01:00
b87ca1fa03 2.0.5 2018-08-11 15:10:28 +02:00
824f872fa5 fix(tests): update 2018-08-11 15:10:27 +02:00
80248c77d0 2.0.4 2018-08-11 15:09:19 +02:00
f592150646 fix(host handling): update 2018-08-11 15:09:19 +02:00
f24652936a 2.0.3 2018-08-11 00:29:16 +02:00
79af6c4a68 fix(CI): accessLevel 2018-08-11 00:29:16 +02:00
fafc757930 2.0.2 2018-08-11 00:25:20 +02:00
ead5e1a7bd fix(CI): now installing stufall alright 2018-08-11 00:25:20 +02:00
ad57be180a 2.0.1 2018-08-10 23:44:31 +02:00
7cc4ce02c9 fix(core): update 2018-08-10 23:44:31 +02:00
70dace595b 2.0.0 2018-08-10 23:10:48 +02:00
9b043d0e0d BREAKING CHANGE(scope): change scope to @pushrocks 2018-08-10 23:10:48 +02:00
381227406b 1.0.6 2016-08-03 14:10:09 +02:00
08d1c292c3 update dependencies 2016-08-03 14:10:03 +02:00
64b0a2deb7 1.0.5 2016-08-03 12:05:18 +02:00
9b661c0ee5 update types versions 2016-08-03 12:05:03 +02:00
8ca91a48e8 1.0.4 2016-08-02 23:58:47 +02:00
39a5683b9e improve snippets 2016-08-02 23:58:00 +02:00
7967334e7d 1.0.3 2016-08-02 23:50:48 +02:00
5a875d1e22 Merge branch 'master' of gitlab.com:pushrocks/smartnginx 2016-08-02 23:48:30 +02:00
4c68d27b6d 1.0.2 2016-08-02 23:47:33 +02:00
1cca4f95bc fix interface name 2016-08-02 23:47:27 +02:00
3cef614bb3 1.0.1 2016-08-02 15:32:10 +02:00
c3c2ab776d consolidate naming and start exporting interfaces 2016-08-02 15:32:06 +02:00
a533fa5de1 Add license 2016-07-25 01:53:33 +00:00
d8a4c3d088 1.0.0 2016-07-25 03:21:33 +02:00
e2639fd0a9 now talking correctly to nginx 2016-07-25 03:21:28 +02:00
b5a27d5108 0.1.0 2016-07-25 02:57:38 +02:00
f32002309d now ending nginx after test 2016-07-25 02:57:17 +02:00
52c3b40879 improve README 2016-07-25 02:02:24 +02:00
6de1352f5f 0.0.9 2016-07-25 01:57:55 +02:00
c55977d5e4 fix tests 2016-07-25 01:57:51 +02:00
ad986c1efe 0.0.8 2016-07-25 01:54:41 +02:00
ca2ff3481e now working as intended 2016-07-25 01:54:36 +02:00
effe9210fc 0.0.7 2016-07-21 02:25:15 +02:00
e49a358b22 added clean method and compiled 2016-07-21 02:24:54 +02:00
a2bf0315ac update deps and exclude any config from git 2016-07-13 16:19:00 +02:00
2caa3c3d1a now creating a valid config with ssl certificates 2016-07-13 13:04:48 +02:00
92307b187d compile 2016-07-12 23:20:08 +02:00
e0757600b6 integrate cert 2016-07-12 23:11:57 +02:00
244b21ca36 0.0.6 2016-07-12 16:31:27 +02:00
87eb7084c0 fox types 2016-07-12 16:30:39 +02:00
e77b3d0355 0.0.5 2016-07-11 16:35:14 +02:00
871ff06040 add nginx child process 2016-07-11 16:34:51 +02:00
43 changed files with 2425 additions and 472 deletions

5
.gitignore vendored
View File

@ -1,4 +1,5 @@
node_modules/
nginxconfig/zones/
nginxconfig/
coverage/
docs/
docs/
.nogit/

View File

@ -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
View 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.

View File

@ -1,20 +1,30 @@
# smartnginx
control nginx from node, TypeScript ready
## Status
[![build status](https://gitlab.com/pushrocks/smartnginx/badges/master/build.svg)](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
View File

@ -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
View File

@ -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=

View File

@ -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<{}>;
}

View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOl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ZQUNqRCxtQkFBbUIsQ0FBQyxJQUFJLENBQUM7Z0JBQ3JCLE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLFFBQVEsSUFBSSxDQUFDLFFBQVEsWUFBWSxDQUFDLENBQUM7Z0JBQzFELElBQUksQ0FBQyxZQUFZLENBQUMsWUFBWSxFQUFFLENBQUM7WUFDckMsQ0FBQyxDQUFDLENBQUM7WUFDSCxZQUFZLENBQUMsSUFBSSxDQUFDLG1CQUFtQixDQUFDLENBQUM7UUFDM0MsQ0FBQztRQUFBLENBQUM7UUFDRixPQUFPLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUM7YUFDdEIsSUFBSSxDQUFDO1lBQ0YsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ25CLENBQUMsQ0FBQyxDQUFDO1FBRVAsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFDTCxDQUFDO0FBNURZLG1CQUFXLGNBNER2QixDQUFBO0FBQUEsQ0FBQyJ9

25
dist/smartnginx.classes.nginxhost.d.ts vendored Normal file
View 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
View 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

View 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
View 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54cHJvY2Vzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguY2xhc3Nlcy5uZ2lueHByb2Nlc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtB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xDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyx3QkFBd0IsQ0FBQyxDQUFDO1FBQ3BELENBQUM7UUFBQSxDQUFDO1FBQ0YsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ2YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7SUFFRDs7T0FFRztJQUNILEtBQUs7UUFDRCxNQUFNLENBQUM7SUFDWCxDQUFDOztBQUNMLENBQUM7QUFqRVksb0JBQVksZUFpRXhCLENBQUEifQ==

View File

@ -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;
}

View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54em9uZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3Vy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UNMLGdCQUFDO0FBQUQsQ0FBQyxBQW5CRCxJQW1CQztBQW5CWSxpQkFBUyxZQW1CckIsQ0FBQTtBQUFBLENBQUMifQ==

View File

@ -1,14 +0,0 @@
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
/**
* starts nginx
*/
export declare let start: (configArg: NginxConfig) => void;
export declare let restart: (configArg: NginxConfig) => void;
/**
* stops nginx
*/
export declare let stop: () => void;
/**
* checks if nginx is in path
*/
export declare let check: () => boolean;

View File

@ -1,22 +0,0 @@
"use strict";
/**
* starts nginx
*/
exports.start = function (configArg) {
};
exports.restart = function (configArg) {
exports.stop();
exports.start(configArg);
};
/**
* stops nginx
*/
exports.stop = function () {
};
/**
* checks if nginx is in path
*/
exports.check = function () {
return;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jb21tYW5kLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jb21tYW5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFJQTs7R0FFRztBQUNRLGFBQUssR0FBRyxVQUFDLFNBQXFCO0FBRXpDLENBQUMsQ0FBQztBQUVTLGVBQU8sR0FBRyxVQUFDLFNBQXFCO0lBQ3ZDLFlBQUksRUFBRSxDQUFDO0lBQ1AsYUFBSyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQ3JCLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ1EsWUFBSSxHQUFHO0FBRWxCLENBQUMsQ0FBQztBQUVGOztHQUVHO0FBQ1EsYUFBSyxHQUFHO0lBQ2YsTUFBTSxDQUFDO0FBQ1gsQ0FBQyxDQUFDIn0=

View File

@ -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;

View File

@ -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

View File

@ -1,7 +1,9 @@
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 declare let shelljs: any;
export import shelljs = require("shelljs");
export import smartfile = require("smartfile");
export import smartstring = require("smartstring");

View File

@ -1,9 +1,11 @@
"use strict";
require("typings-global");
exports.beautylog = require("beautylog");
exports.cert = require("cert");
exports.childProcess = require("child_process");
exports.path = require("path");
exports.q = require("q");
exports.shelljs = require("shelljs");
exports.smartfile = require("smartfile");
exports.smartstring = require("smartstring");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsWUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNwQixlQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQzFCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixvQkFBWSxXQUFXLGVBQWUsQ0FBQyxDQUFDO0FBQ3hDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9

View File

@ -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;

View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5zbmlwcGV0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguc25pcHBldHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDckMsMkJBQW1CLEdBQUc7SUFDaEMsSUFBSSxVQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDLDY0Q0FrRXJELENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDbkIsQ0FBQyxDQUFBO0FBR1UsMkJBQW1CLEdBQUcsVUFBQyxXQUFrQixFQUFDLGdCQUF1QjtJQUMzRSxJQUFJLFVBQVUsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLE1BQU0sQ0FBQyxTQUFTLENBQUMsb0JBQzFDLFdBQVcseUJBQ1osZ0JBQWdCLHlFQUtYLFdBQVcsMENBQ0UsV0FBVyxvR0FLeEIsV0FBVywyQ0FDRyxXQUFXLDZEQUNQLFdBQVcsdUVBR3RCLFdBQVcsMEhBT2pDLENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDbkIsQ0FBQyxDQUFDIn0=
//# sourceMappingURL=data:application/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x.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
View File

@ -0,0 +1,8 @@
{
"npmci": {
"npmAccessLevel": "public"
},
"npmdocker": {
}
}

1603
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,14 @@
{
"name": "smartnginx",
"version": "0.0.4",
"name": "@pushrocks/smartnginx",
"version": "2.0.21",
"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,16 +24,20 @@
},
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
"dependencies": {
"@types/q": "0.0.25-alpha",
"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"
}
}

1
qenv.yml Normal file
View File

@ -0,0 +1 @@
vars:

2
test/test.d.ts vendored
View File

@ -1,2 +0,0 @@
import "typings-test";
import "should";

View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTy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UMsZUFBZSxDQUFDLENBQUM7WUFDN0MsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQztRQUNILFFBQVEsQ0FBQyxXQUFXLEVBQUM7WUFDakIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDO2dCQUN6QyxlQUFlLENBQUMsTUFBTSxFQUFFLENBQUM7WUFDN0IsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFDLENBQUMifQ==

View File

@ -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();

View File

@ -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';

View File

@ -0,0 +1,6 @@
export interface IHostConfig {
hostName: string;
destination: string;
privateKey: string;
publicKey: string;
}

0
ts/interfaces/index.ts Normal file
View File

View 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);
};
};
};

View 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);
}
}

View 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;
}
}

View File

@ -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);
};
};

View 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();
}
}
}

View File

@ -1,29 +0,0 @@
import * as plugins from "./smartnginx.plugins";
import {NginxConfig} from "./smartnginx.classes.nginxconfig";
import {NginxZone} from "./smartnginx.classes.nginxzone";
/**
* starts nginx
*/
export let start = (configArg:NginxConfig) => {
};
export let restart = (configArg:NginxConfig) => {
stop();
start(configArg);
}
/**
* stops nginx
*/
export let stop = () => {
};
/**
* checks if nginx is in path
*/
export let check = ():boolean => {
return;
};

View File

@ -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');

View File

@ -1,7 +1,14 @@
import "typings-global";
export import cert = require("cert");
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 };

View File

@ -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,47 @@ 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} {
keepalive 100;
server ${destinationIpArg};
}
server {
# The keepalive parameter sets the maximum number of idle keepalive connections
# to upstream servers that are preserved in the cache of each worker process. When
# this number is exceeded, the least recently used connections are closed.
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;
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_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
proxy_pass http://${hostNameArg};
}
}
`);
return zoneConfig;
return hostConfig;
};

17
tslint.json Normal file
View 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"
}