Compare commits
108 Commits
Author | SHA1 | Date | |
---|---|---|---|
a4c8b789ad | |||
b4378e305a | |||
5ff0980908 | |||
e60257d761 | |||
e94f0edafb | |||
c417d96e48 | |||
c5b1dbb46e | |||
893a2e2709 | |||
01f0dc6b20 | |||
736a42066c | |||
44403863d1 | |||
5be21fa100 | |||
042167c01e | |||
db38d038ef | |||
a4d8a46360 | |||
84e5c10129 | |||
98a2871f08 | |||
9bb847210a | |||
91d4ba5715 | |||
3ee2988964 | |||
221f1f6237 | |||
0a6fbf588e | |||
1a8546af6e | |||
9e01bdb8e2 | |||
33833fbc6c | |||
97b5678fe4 | |||
9b96984413 | |||
0de412b842 | |||
64bcce9e23 | |||
390812ec33 | |||
a672bb920f | |||
c3fabb6107 | |||
b4ebdbae47 | |||
c55d2dcf10 | |||
7274d5ea8a | |||
1ec733c2a9 | |||
3ef14d8ac7 | |||
f332bf95fe | |||
6acad8a306 | |||
6ae672f707 | |||
3d263e2181 | |||
85639f29af | |||
85448a21fc | |||
3b85c4a37e | |||
67dd650dce | |||
92eaf5f19a | |||
fcf9a61b1d | |||
fbd258a876 | |||
c65b8fc1af | |||
b7b588d713 | |||
00d672c135 | |||
6a1e778b49 | |||
4cfb26f62f | |||
7ba3ad0b21 | |||
cd93ec2560 | |||
ede884930e | |||
1049920efd | |||
b7a34403c5 | |||
987e19372a | |||
0b97aaee91 | |||
b87ca1fa03 | |||
824f872fa5 | |||
80248c77d0 | |||
f592150646 | |||
f24652936a | |||
79af6c4a68 | |||
fafc757930 | |||
ead5e1a7bd | |||
ad57be180a | |||
7cc4ce02c9 | |||
70dace595b | |||
9b043d0e0d | |||
381227406b | |||
08d1c292c3 | |||
64b0a2deb7 | |||
9b661c0ee5 | |||
8ca91a48e8 | |||
39a5683b9e | |||
7967334e7d | |||
5a875d1e22 | |||
4c68d27b6d | |||
1cca4f95bc | |||
3cef614bb3 | |||
c3c2ab776d | |||
a533fa5de1 | |||
d8a4c3d088 | |||
e2639fd0a9 | |||
b5a27d5108 | |||
f32002309d | |||
52c3b40879 | |||
6de1352f5f | |||
c55977d5e4 | |||
ad986c1efe | |||
ca2ff3481e | |||
effe9210fc | |||
e49a358b22 | |||
a2bf0315ac | |||
2caa3c3d1a | |||
92307b187d | |||
e0757600b6 | |||
244b21ca36 | |||
87eb7084c0 | |||
e77b3d0355 | |||
871ff06040 | |||
1f2105f75e | |||
43e8549042 | |||
9864dcc56a | |||
bd6c76cbfd |
3
.gitignore
vendored
3
.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
|
||||||
tags:
|
- npmci npm test stable
|
||||||
- docker
|
only:
|
||||||
|
- tags
|
||||||
release:
|
tags:
|
||||||
stage: release
|
- docker
|
||||||
script:
|
- notpriv
|
||||||
- npmci publish
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
environment: npmjs-com_registry
|
||||||
|
script:
|
||||||
|
- 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.
|
24
README.md
24
README.md
@ -1,20 +1,30 @@
|
|||||||
# smartnginx
|
# smartnginx
|
||||||
|
|
||||||
control nginx from node, TypeScript ready
|
control nginx from node, TypeScript ready
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
[](https://gitlab.com/pushrocks/smartnginx/commits/master)
|
[](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
|
## Usage
|
||||||
|
|
||||||
We recommend the use of TypeScript! :)
|
We recommend the use of TypeScript! :)
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import * as smartnginx from "smartnginx";
|
import * as smartnginx from 'smartnginx';
|
||||||
myNginxConfig = new smartnginx.NginxConfig();
|
const smartnginxInstance = new smartnginx.SmartNginx();
|
||||||
myNginxZone = new smartnginx.NginxZone({
|
myNginxHost = new smartnginx.NginxHost({
|
||||||
zoneName:"some.example.com",
|
hostName: 'some.example.com',
|
||||||
type:"reverseProxy",
|
type: 'reverseProxy',
|
||||||
destination:"192.192.192.192" // some destination IP
|
destination: '192.192.192.192' // some destination IP
|
||||||
});
|
});
|
||||||
myNginxConfig.addZone(myNginxZone); // adds the zone to the config
|
myNginxConfig.addZone(myNginxZone); // adds the zone to the config
|
||||||
myNginxConfig.deploy(); // deploys the referenced NginxConfig and restarts nginx
|
myNginxConfig.deploy(); // deploys the referenced NginxConfig and gracefully reloads it
|
||||||
```
|
```
|
7
dist/index.d.ts
vendored
7
dist/index.d.ts
vendored
@ -1,4 +1,3 @@
|
|||||||
import * as CommandModule from "./smartnginx.command";
|
export * from "./smartnginx.classes.nginxconfig";
|
||||||
export { NginxConfig } from "./smartnginx.classes.nginxconfig";
|
export * from "./smartnginx.classes.nginxprocess";
|
||||||
export { NginxZone, zoneTypes } from "./smartnginx.classes.nginxzone";
|
export * from "./smartnginx.classes.nginxhost";
|
||||||
export declare let command: typeof CommandModule;
|
|
||||||
|
16
dist/index.js
vendored
16
dist/index.js
vendored
@ -1,11 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var CommandModule = require("./smartnginx.command");
|
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"));
|
||||||
var smartnginx_classes_nginxzone_1 = require("./smartnginx.classes.nginxzone");
|
__export(require("./smartnginx.classes.nginxhost"));
|
||||||
exports.NginxZone = smartnginx_classes_nginxzone_1.NginxZone;
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsVUFBVTtBQUNWLGlCQUFjLGtDQUFrQyxDQUFDLEVBQUE7QUFDakQsaUJBQWMsbUNBQW1DLENBQUMsRUFBQTtBQUNsRCxpQkFBYyxnQ0FBZ0MsQ0FBQyxFQUFBIn0=
|
||||||
exports.zoneTypes = smartnginx_classes_nginxzone_1.zoneTypes;
|
|
||||||
// exports
|
|
||||||
exports.command = CommandModule;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQ0EsSUFBWSxhQUFhLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUV0RCxVQUFVO0FBQ1YsK0NBQTBCLGtDQUFrQyxDQUFDO0FBQXJELG1FQUFxRDtBQUM3RCw2Q0FBa0MsZ0NBQWdDLENBQUM7QUFBM0QsNkRBQVM7QUFBQyw2REFBaUQ7QUFFbkUsVUFBVTtBQUNDLGVBQU8sR0FBRyxhQUFhLENBQUMifQ==
|
|
23
dist/smartnginx.classes.nginxconfig.d.ts
vendored
23
dist/smartnginx.classes.nginxconfig.d.ts
vendored
@ -1,10 +1,19 @@
|
|||||||
import { NginxZone } from "./smartnginx.classes.nginxzone";
|
/// <reference types="q" />
|
||||||
|
import * as plugins from "./smartnginx.plugins";
|
||||||
|
import { NginxHost } from "./smartnginx.classes.nginxhost";
|
||||||
|
import { NginxProcess } from "./smartnginx.classes.nginxprocess";
|
||||||
|
/**
|
||||||
|
* main class that manages a NginxInstance
|
||||||
|
*/
|
||||||
export declare class NginxConfig {
|
export declare class NginxConfig {
|
||||||
zones: NginxZone[];
|
hosts: NginxHost[];
|
||||||
|
cert: plugins.cert.Cert;
|
||||||
|
nginxProcess: NginxProcess;
|
||||||
isDeployed: boolean;
|
isDeployed: boolean;
|
||||||
constructor();
|
constructor(optionsArg: plugins.cert.ICertConstructorOptions);
|
||||||
addZone(zoneArg: NginxZone): void;
|
addHost(nginxHostArg: NginxHost): void;
|
||||||
listZones(): NginxZone[];
|
listHosts(): NginxHost[];
|
||||||
removeZones(zoneArg: NginxZone): void;
|
removeHost(nginxHostArg: NginxHost): void;
|
||||||
deploy(nginxRestartArg?: boolean): void;
|
clean(): void;
|
||||||
|
deploy(): plugins.q.Promise<{}>;
|
||||||
}
|
}
|
||||||
|
89
dist/smartnginx.classes.nginxconfig.js
vendored
89
dist/smartnginx.classes.nginxconfig.js
vendored
@ -1,44 +1,71 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var plugins = require("./smartnginx.plugins");
|
const plugins = require("./smartnginx.plugins");
|
||||||
var paths = require("./smartnginx.paths");
|
const paths = require("./smartnginx.paths");
|
||||||
var command = require("./smartnginx.command");
|
const snippets = require("./smartnginx.snippets");
|
||||||
var allConfigs = [];
|
const smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
|
||||||
var NginxConfig = (function () {
|
let allConfigs = [];
|
||||||
function NginxConfig() {
|
/**
|
||||||
|
* 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.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 (nginxRestartArg) {
|
this.hosts = [];
|
||||||
if (nginxRestartArg === void 0) { nginxRestartArg = false; }
|
}
|
||||||
plugins.smartfile.fs.remove(paths.nginxZoneBase);
|
// handle deployment of hosts
|
||||||
plugins.smartfile.fs.ensureDir(paths.nginxZoneBase);
|
deploy() {
|
||||||
for (var _i = 0, allConfigs_1 = allConfigs; _i < allConfigs_1.length; _i++) {
|
let done = plugins.q.defer();
|
||||||
var config = allConfigs_1[_i];
|
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;
|
config.isDeployed = false;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
this.isDeployed = true;
|
this.isDeployed = true;
|
||||||
for (var _a = 0, _b = this.zones; _a < _b.length; _a++) {
|
// write base config
|
||||||
var zone = _b[_a];
|
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
|
||||||
zone.deploy();
|
// 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);
|
||||||
}
|
}
|
||||||
if (nginxRestartArg) {
|
|
||||||
command.restart(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
;
|
;
|
||||||
return NginxConfig;
|
plugins.q.all(promiseArray)
|
||||||
}());
|
.then(() => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
}
|
||||||
exports.NginxConfig = NginxConfig;
|
exports.NginxConfig = NginxConfig;
|
||||||
;
|
;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELElBQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsSUFBWSxPQUFPLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUVoRCxJQUFJLFVBQVUsR0FBaUIsRUFBRSxDQUFDO0FBRWxDO0lBR0k7UUFEQSxlQUFVLEdBQVcsS0FBSyxDQU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BSyxDQUFDLGFBQWEsQ0FDdEIsQ0FBQztRQUNGLGVBQWU7UUFDZixJQUFJLFlBQVksR0FBRyxFQUFFLENBQUM7UUFDdEIsR0FBRyxDQUFDLENBQUMsSUFBSSxJQUFJLElBQUksSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUM7WUFDMUIsSUFBSSxtQkFBbUIsR0FBRyxJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQztZQUNqRCxtQkFBbUIsQ0FBQyxJQUFJLENBQUM7Z0JBQ3JCLE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLFFBQVEsSUFBSSxDQUFDLFFBQVEsWUFBWSxDQUFDLENBQUM7Z0JBQzFELElBQUksQ0FBQyxZQUFZLENBQUMsWUFBWSxFQUFFLENBQUM7WUFDckMsQ0FBQyxDQUFDLENBQUM7WUFDSCxZQUFZLENBQUMsSUFBSSxDQUFDLG1CQUFtQixDQUFDLENBQUM7UUFDM0MsQ0FBQztRQUFBLENBQUM7UUFDRixPQUFPLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUM7YUFDdEIsSUFBSSxDQUFDO1lBQ0YsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ25CLENBQUMsQ0FBQyxDQUFDO1FBRVAsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFDTCxDQUFDO0FBNURZLG1CQUFXLGNBNER2QixDQUFBO0FBQUEsQ0FBQyJ9
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54cHJvY2Vzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguY2xhc3Nlcy5uZ2lueHByb2Nlc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDaEQsTUFBWSxLQUFLLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUk1Qzs7R0FFRztBQUNIO0lBSUksWUFBWSxjQUFjO1FBSDFCLFlBQU8sR0FBWSxLQUFLLENBQUM7UUFJckIsSUFBSSxDQUFDLFdBQVcsR0FBRyxjQUFjLENBQUM7SUFDdEMsQ0FBQzs7SUFFRDs7T0FFRztJQUNILEtBQUs7UUFDRCxJQUFJLElBQ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M7SUFDWCxDQUFDOztBQUNMLENBQUM7QUFqRVksb0JBQVksZUFpRXhCLENBQUEifQ==
|
14
dist/smartnginx.classes.nginxzone.d.ts
vendored
14
dist/smartnginx.classes.nginxzone.d.ts
vendored
@ -1,14 +0,0 @@
|
|||||||
export declare enum zoneTypes {
|
|
||||||
reverseProxy = 0,
|
|
||||||
static = 1,
|
|
||||||
}
|
|
||||||
export declare class NginxZone {
|
|
||||||
zoneName: string;
|
|
||||||
configString: string;
|
|
||||||
constructor(optionsArg: {
|
|
||||||
zoneName: string;
|
|
||||||
type: zoneTypes;
|
|
||||||
destination: string;
|
|
||||||
});
|
|
||||||
deploy(): void;
|
|
||||||
}
|
|
24
dist/smartnginx.classes.nginxzone.js
vendored
24
dist/smartnginx.classes.nginxzone.js
vendored
@ -1,24 +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.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,eyJ2ZXJzaW9uIjozLCJma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ored
14
dist/smartnginx.command.d.ts
vendored
@ -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;
|
|
22
dist/smartnginx.command.js
vendored
22
dist/smartnginx.command.js
vendored
@ -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=
|
|
4
dist/smartnginx.paths.d.ts
vendored
4
dist/smartnginx.paths.d.ts
vendored
@ -1,3 +1,5 @@
|
|||||||
export declare let packageBase: string;
|
export declare let packageBase: string;
|
||||||
export declare let nginxConfigBase: string;
|
export declare let nginxConfigBase: string;
|
||||||
export declare let nginxZoneBase: string;
|
export declare let nginxHostFileBase: string;
|
||||||
|
export declare let nginxCertBase: string;
|
||||||
|
export declare let nginxConfFile: string;
|
||||||
|
12
dist/smartnginx.paths.js
vendored
12
dist/smartnginx.paths.js
vendored
@ -1,6 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var plugins = require("./smartnginx.plugins");
|
const plugins = require("./smartnginx.plugins");
|
||||||
|
// directories
|
||||||
exports.packageBase = plugins.path.join(__dirname, "../");
|
exports.packageBase = plugins.path.join(__dirname, "../");
|
||||||
exports.nginxConfigBase = plugins.path.join(exports.packageBase, "nginxconfig/");
|
exports.nginxConfigBase = plugins.path.join(exports.packageBase, "nginxconfig");
|
||||||
exports.nginxZoneBase = plugins.path.join(exports.nginxConfigBase, "zones");
|
exports.nginxHostFileBase = plugins.path.join(exports.nginxConfigBase, "hosts");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQVksT0FBTyxXQUFNLHNCQUV6QixDQUFDLENBRjhDO0FBRXBDLG1CQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFDO0FBQ2pELHVCQUFlLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsbUJBQVcsRUFBQyxjQUFjLENBQUMsQ0FBQztBQUNoRSxxQkFBYSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHVCQUFlLEVBQUMsT0FBTyxDQUFDLENBQUMifQ==
|
exports.nginxCertBase = plugins.path.join(exports.nginxConfigBase, "cert");
|
||||||
|
// files
|
||||||
|
exports.nginxConfFile = plugins.path.join(exports.nginxConfigBase, "nginx.conf");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUd6QixDQUFDLENBSDhDO0FBRS9DLGNBQWM7QUFDSCxtQkFBVyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxLQUFLLENBQUMsQ0FBQztBQUNqRCx1QkFBZSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLG1CQUFXLEVBQUMsYUFBYSxDQUFDLENBQUM7QUFDL0QseUJBQWlCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsdUJBQWUsRUFBQyxPQUFPLENBQUMsQ0FBQztBQUMvRCxxQkFBYSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHVCQUFlLEVBQUMsTUFBTSxDQUFDLENBQUM7QUFFckUsUUFBUTtBQUNHLHFCQUFhLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsdUJBQWUsRUFBQyxZQUFZLENBQUMsQ0FBQyJ9
|
5
dist/smartnginx.plugins.d.ts
vendored
5
dist/smartnginx.plugins.d.ts
vendored
@ -1,6 +1,9 @@
|
|||||||
import "typings-global";
|
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 path = require("path");
|
||||||
export import q = require("q");
|
export import q = require("q");
|
||||||
export declare let shelljs: any;
|
export import shelljs = require("shelljs");
|
||||||
export import smartfile = require("smartfile");
|
export import smartfile = require("smartfile");
|
||||||
|
export import smartstring = require("smartstring");
|
||||||
|
5
dist/smartnginx.plugins.js
vendored
5
dist/smartnginx.plugins.js
vendored
@ -1,8 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
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.path = require("path");
|
||||||
exports.q = require("q");
|
exports.q = require("q");
|
||||||
exports.shelljs = require("shelljs");
|
exports.shelljs = require("shelljs");
|
||||||
exports.smartfile = require("smartfile");
|
exports.smartfile = require("smartfile");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsWUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNwQixlQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQzFCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUMifQ==
|
exports.smartstring = require("smartstring");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixvQkFBWSxXQUFXLGVBQWUsQ0FBQyxDQUFDO0FBQ3hDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9
|
4
dist/smartnginx.snippets.d.ts
vendored
4
dist/smartnginx.snippets.d.ts
vendored
@ -1,2 +1,2 @@
|
|||||||
export declare let getBaseConfigString: () => void;
|
export declare let getBaseConfigString: () => string;
|
||||||
export declare let getZoneConfigString: (zoneNameArg: string, destinationIpArg: string) => string;
|
export declare let getHostConfigString: (hostNameArg: string, destinationIpArg: string) => string;
|
||||||
|
106
dist/smartnginx.snippets.js
vendored
106
dist/smartnginx.snippets.js
vendored
@ -1,9 +1,103 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
exports.getBaseConfigString = function () {
|
const plugins = require("./smartnginx.plugins");
|
||||||
var baseConfig = "\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 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) {
|
exports.getHostConfigString = (hostNameArg, destinationIpArg) => {
|
||||||
var zoneConfig = ("\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").trim();
|
let hostConfig = plugins.smartstring.indent.normalize(`
|
||||||
return zoneConfig;
|
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;
|
||||||
};
|
};
|
||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ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O2FBOEQxQyxLQUFLLENBQUMsaUJBQWlCOzs7O0VBSWxDLENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDbkIsQ0FBQyxDQUFBO0FBR1UsMkJBQW1CLEdBQUcsQ0FBQyxXQUFrQixFQUFDLGdCQUF1QjtJQUMzRSxJQUFJLFVBQVUsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLE1BQU0sQ0FBQyxTQUFTLENBQUM7YUFDMUMsV0FBVztZQUNaLGdCQUFnQjs7Ozs7aUJBS1gsV0FBVzs4QkFDRSxXQUFXOzs7OztpQkFLeEIsV0FBVztxQkFDUCxLQUFLLENBQUMsYUFBYSxJQUFJLFdBQVc7eUJBQzlCLEtBQUssQ0FBQyxhQUFhLElBQUksV0FBVzs7O3dCQUduQyxXQUFXOzs7Ozs7O0VBT2pDLENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDbkIsQ0FBQyxDQUFDIn0=
|
@ -1,65 +0,0 @@
|
|||||||
user www-data;
|
|
||||||
worker_processes auto;
|
|
||||||
pid /run/nginx.pid;
|
|
||||||
|
|
||||||
events {
|
|
||||||
worker_connections 768;
|
|
||||||
# multi_accept on;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
server_names_hash_bucket_size 128;
|
|
||||||
|
|
||||||
##
|
|
||||||
# Basic Settings
|
|
||||||
##
|
|
||||||
|
|
||||||
sendfile on;
|
|
||||||
tcp_nopush on;
|
|
||||||
tcp_nodelay on;
|
|
||||||
keepalive_timeout 65;
|
|
||||||
types_hash_max_size 2048;
|
|
||||||
# server_tokens off;
|
|
||||||
|
|
||||||
# server_names_hash_bucket_size 64;
|
|
||||||
# server_name_in_redirect off;
|
|
||||||
|
|
||||||
include /etc/nginx/mime.types;
|
|
||||||
default_type application/octet-stream;
|
|
||||||
|
|
||||||
##
|
|
||||||
# SSL Settings
|
|
||||||
##
|
|
||||||
|
|
||||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
|
|
||||||
ssl_prefer_server_ciphers on;
|
|
||||||
|
|
||||||
##
|
|
||||||
# Logging Settings
|
|
||||||
##
|
|
||||||
|
|
||||||
access_log /var/log/nginx/access.log;
|
|
||||||
error_log /var/log/nginx/error.log;
|
|
||||||
|
|
||||||
##
|
|
||||||
# Gzip Settings
|
|
||||||
##
|
|
||||||
|
|
||||||
gzip on;
|
|
||||||
gzip_disable "msie6";
|
|
||||||
|
|
||||||
# gzip_vary on;
|
|
||||||
# gzip_proxied any;
|
|
||||||
# gzip_comp_level 6;
|
|
||||||
# gzip_buffers 16 8k;
|
|
||||||
# gzip_http_version 1.1;
|
|
||||||
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
|
||||||
|
|
||||||
##
|
|
||||||
# Virtual Host Configs
|
|
||||||
##
|
|
||||||
|
|
||||||
include /etc/nginx/conf.d/*.conf;
|
|
||||||
include /etc/nginx/sites-enabled/*;
|
|
||||||
}
|
|
||||||
daemon off;
|
|
8
npmextra.json
Normal file
8
npmextra.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"npmci": {
|
||||||
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"npmdocker": {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
1645
package-lock.json
generated
Normal file
1645
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@ -1,11 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "smartnginx",
|
"name": "@pushrocks/smartnginx",
|
||||||
"version": "0.0.2",
|
"version": "2.0.35",
|
||||||
|
"private": false,
|
||||||
"description": "control nginx from node, TypeScript ready",
|
"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,16 +24,21 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
|
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "0.0.25-alpha",
|
"@pushrocks/lik": "^3.0.4",
|
||||||
"cert": "0.0.13",
|
"@pushrocks/smartfile": "^6.0.11",
|
||||||
"q": "^1.4.1",
|
"@pushrocks/smartlog": "^2.0.11",
|
||||||
"shelljs": "^0.7.0",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"smartfile": "^4.0.10",
|
"@pushrocks/smartshell": "^2.0.13",
|
||||||
"smartstring": "^2.0.10"
|
"@pushrocks/smartstring": "^3.0.8",
|
||||||
|
"@pushrocks/smartunique": "^3.0.1"
|
||||||
},
|
},
|
||||||
"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/qenv": "^4.0.0",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
|
"tslint": "^5.12.1",
|
||||||
|
"tslint-config-prettier": "^1.17.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import "typings-test";
|
|
||||||
import "should";
|
|
27
test/test.js
27
test/test.js
@ -1,27 +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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQixJQUFZLFVBQVUsV0FBTSxlQUFlLENBQUMsQ0FBQTtBQUU1QyxRQUFRLENBQUMsWUFBWSxFQUFDO0lBQ2xCLElBQUksZUFBc0MsQ0FBQztJQUMzQyxJQUFJLGVBQW9DLENBQUM7SUFDekMsSUFBSSxlQUFvQyxDQUFDO0lBQ3pDLFFBQVEsQ0FBQyxXQUFXLEVBQUM7UUFDakIsRUFBRSxDQUFDLCtEQUE2RCxFQUFDO1lBQzdELGVBQWUsR0FBRyxJQUFJLFVBQVUsQ0FBQyxTQUFTLENBQUM7Z0JBQ3ZDLFFBQVEsRUFBQyxlQUFlO2dCQUN4QixJQUFJLEVBQUMsVUFBVSxDQUFDLFNBQVMsQ0FBQyxZQUFZO2dCQUN0QyxXQUFXLEVBQUMsaUJBQWlCO2FBQ2hDLENBQUMsQ0FBQztZQUNILGVBQWUsQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxVQUFVLENBQUMsU0FBUyxDQUFDLENBQUM7WUFDM0QsT0FBTyxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUMsWUFBWSxDQUFDLENBQUM7UUFDOUMsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDLENBQUMsQ0FBQztJQUNILFFBQVEsQ0FBQyxhQUFhLEVBQUM7UUFDbkIsRUFBRSxDQUFDLGlFQUErRCxFQUFDO1lBQy9ELGVBQWUsR0FBRyxJQUFJLFVBQVUsQ0FBQyxXQUFXLEVBQUUsQ0FBQztZQUMvQyxlQUFlLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsVUFBVSxDQUFDLFdBQVcsQ0FBQyxDQUFDO1FBQ2pFLENBQUMsQ0FBQyxDQUFDO0lBQ1AsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyJ9
|
|
77
test/test.ts
77
test/test.ts
@ -1,26 +1,55 @@
|
|||||||
import "typings-test";
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import "should";
|
import path = require('path');
|
||||||
import * as smartnginx from "../dist/index";
|
|
||||||
|
|
||||||
describe("smartnginx",function(){
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
let testNginxConfig:smartnginx.NginxConfig;
|
const testQenv = new Qenv('./', './.nogit/');
|
||||||
let testNginxZone01:smartnginx.NginxZone;
|
|
||||||
let testNginxZone02:smartnginx.NginxZone;
|
import * as smartnginx from '../ts/index';
|
||||||
describe("NginxZone",function(){
|
|
||||||
it(`"new NginxZone()" should produce an instance of NginxConfig`,function(){
|
let testSmartNginx: smartnginx.SmartNginx;
|
||||||
testNginxZone01 = new smartnginx.NginxZone({
|
let testNginxZone01: smartnginx.NginxHost;
|
||||||
zoneName:"test1.bleu.de",
|
let testNginxZone02: smartnginx.NginxHost;
|
||||||
type:smartnginx.zoneTypes.reverseProxy,
|
|
||||||
destination:"192.192.192.192"
|
tap.test('should create a valid instance of SmartNginx', async () => {
|
||||||
});
|
testSmartNginx = new smartnginx.SmartNginx({});
|
||||||
testNginxZone01.should.be.instanceof(smartnginx.NginxZone);
|
expect(testSmartNginx).to.be.instanceof(smartnginx.SmartNginx);
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test(`should produce an instance of NginxConfig`, async () => {
|
||||||
|
testNginxZone01 = new smartnginx.NginxHost(testSmartNginx, {
|
||||||
|
hostName: 'test100.bleu.de',
|
||||||
|
destination: '192.192.192.191',
|
||||||
|
destinationPort: 3000,
|
||||||
|
privateKey: 'some private',
|
||||||
|
publicKey: 'some public'
|
||||||
|
});
|
||||||
|
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
|
||||||
|
hostName: 'test102.bleu.de',
|
||||||
|
destination: '192.192.192.192',
|
||||||
|
destinationPort: 3050,
|
||||||
|
privateKey: 'some private',
|
||||||
|
publicKey: 'some public'
|
||||||
|
});
|
||||||
|
expect(testNginxZone01).to.be.instanceof(smartnginx.NginxHost);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('.addHostCandidate() should add a zone to NginxConfig Object', async () => {
|
||||||
|
testSmartNginx.addHostCandidate(testNginxZone01);
|
||||||
|
testSmartNginx.addHostCandidate(testNginxZone02);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('.deploy() should deploy a config from an instance', async () => {
|
||||||
|
await testSmartNginx.deploy();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should not redeploy', async () => {
|
||||||
|
testSmartNginx.addHostCandidate(testNginxZone01);
|
||||||
|
testSmartNginx.addHostCandidate(testNginxZone02);
|
||||||
|
await testSmartNginx.deploy();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('.stop() should end the process', async () => {
|
||||||
|
testSmartNginx.nginxProcess.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
11
ts/index.ts
11
ts/index.ts
@ -1,9 +1,6 @@
|
|||||||
import * as plugins from "./smartnginx.plugins";
|
import * as plugins from './smartnginx.plugins';
|
||||||
import * as CommandModule from "./smartnginx.command";
|
|
||||||
|
|
||||||
// classes
|
// classes
|
||||||
export {NginxConfig} from "./smartnginx.classes.nginxconfig";
|
export * from './smartnginx.classes.smartnginx';
|
||||||
export {NginxZone,zoneTypes} from "./smartnginx.classes.nginxzone";
|
export * from './smartnginx.classes.nginxprocess';
|
||||||
|
export * from './smartnginx.classes.nginxhost';
|
||||||
// exports
|
|
||||||
export let command = CommandModule;
|
|
||||||
|
7
ts/interfaces/hostconfig.ts
Normal file
7
ts/interfaces/hostconfig.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export interface IHostConfig {
|
||||||
|
hostName: string;
|
||||||
|
destination: string;
|
||||||
|
destinationPort: number;
|
||||||
|
privateKey: string;
|
||||||
|
publicKey: string;
|
||||||
|
}
|
0
ts/interfaces/index.ts
Normal file
0
ts/interfaces/index.ts
Normal file
@ -1,41 +0,0 @@
|
|||||||
import * as plugins from "./smartnginx.plugins";
|
|
||||||
import * as paths from "./smartnginx.paths";
|
|
||||||
import * as command from "./smartnginx.command";
|
|
||||||
import {NginxZone} from "./smartnginx.classes.nginxzone";
|
|
||||||
let allConfigs:NginxConfig[] = [];
|
|
||||||
|
|
||||||
export class NginxConfig {
|
|
||||||
zones:NginxZone[];
|
|
||||||
isDeployed:boolean = false;
|
|
||||||
constructor(){
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// interact with Zones
|
|
||||||
addZone(zoneArg:NginxZone){
|
|
||||||
|
|
||||||
}
|
|
||||||
listZones():NginxZone[] {
|
|
||||||
return this.zones;
|
|
||||||
};
|
|
||||||
removeZones(zoneArg:NginxZone){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle deployment of zones
|
|
||||||
deploy(nginxRestartArg:boolean = false){
|
|
||||||
plugins.smartfile.fs.remove(paths.nginxZoneBase);
|
|
||||||
plugins.smartfile.fs.ensureDir(paths.nginxZoneBase);
|
|
||||||
for(let config of allConfigs){
|
|
||||||
config.isDeployed = false;
|
|
||||||
};
|
|
||||||
this.isDeployed = true;
|
|
||||||
for(let zone of this.zones){
|
|
||||||
zone.deploy();
|
|
||||||
}
|
|
||||||
if(nginxRestartArg){
|
|
||||||
command.restart(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
57
ts/smartnginx.classes.nginxhost.ts
Normal file
57
ts/smartnginx.classes.nginxhost.ts
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
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 destinationPort: number;
|
||||||
|
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.destinationPort = optionsArg.destinationPort;
|
||||||
|
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
|
||||||
|
this.configString = snippets.getHostConfigString(this.hostName, this.destination, this.destinationPort);
|
||||||
|
plugins.smartfile.memory.toFsSync(this.configString, filePathConfig);
|
||||||
|
|
||||||
|
// write ssl
|
||||||
|
plugins.smartfile.memory.toFsSync(this.privateKey, filePathPrivate);
|
||||||
|
plugins.smartfile.memory.toFsSync(this.publicKey, filePathPublic);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
69
ts/smartnginx.classes.nginxprocess.ts
Normal file
69
ts/smartnginx.classes.nginxprocess.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import * as plugins from './smartnginx.plugins';
|
||||||
|
import * as paths from './smartnginx.paths';
|
||||||
|
import { SmartNginx } from './smartnginx.classes.smartnginx';
|
||||||
|
import { NginxHost } from './smartnginx.classes.nginxhost';
|
||||||
|
|
||||||
|
import { Smartshell } from '@pushrocks/smartshell';
|
||||||
|
|
||||||
|
import { ChildProcess } from 'child_process';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* manages a nginxprocess for an NginxConfig
|
||||||
|
*/
|
||||||
|
export class NginxProcess {
|
||||||
|
public started: boolean = false;
|
||||||
|
public smartNginxRef: SmartNginx;
|
||||||
|
private nginxChildProcess: ChildProcess;
|
||||||
|
private smartshellInstance = new Smartshell({
|
||||||
|
executor: 'bash'
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor(nginxRefArg: SmartNginx) {
|
||||||
|
this.smartNginxRef = nginxRefArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* start nginx
|
||||||
|
*/
|
||||||
|
public async start() {
|
||||||
|
if (!this.nginxChildProcess) {
|
||||||
|
this.nginxChildProcess = (await this.smartshellInstance.execStreaming(
|
||||||
|
`nginx -c ${paths.nginxConfFile}`
|
||||||
|
)).childProcess;
|
||||||
|
}
|
||||||
|
this.started = true;
|
||||||
|
plugins.smartlog.defaultLogger.log('info', 'started Nginx!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reload config
|
||||||
|
*/
|
||||||
|
public async reloadConfig() {
|
||||||
|
if (!this.started) {
|
||||||
|
this.start();
|
||||||
|
} else {
|
||||||
|
await this.smartshellInstance.exec('nginx -s reload');
|
||||||
|
}
|
||||||
|
this.smartNginxRef.logger.log('info', 'NginxProcess has loaded the new config!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stop the nginx instance
|
||||||
|
*/
|
||||||
|
public async stop() {
|
||||||
|
if (this.nginxChildProcess) {
|
||||||
|
this.smartshellInstance.exec('nginx -s quit');
|
||||||
|
this.started = false;
|
||||||
|
this.smartNginxRef.logger.log('info', 'stopped Nginx!');
|
||||||
|
} else {
|
||||||
|
this.smartNginxRef.logger.log('info', 'nginx already stopped!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks if nginx is in path
|
||||||
|
*/
|
||||||
|
public check(): boolean {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +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
|
|
||||||
configString:string; // the actual zone config file as string
|
|
||||||
constructor(optionsArg:{
|
|
||||||
zoneName:string,
|
|
||||||
type:zoneTypes,
|
|
||||||
destination:string
|
|
||||||
}){
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
};
|
|
125
ts/smartnginx.classes.smartnginx.ts
Normal file
125
ts/smartnginx.classes.smartnginx.ts
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
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 &&
|
||||||
|
hostCandidateArg.destinationPort === deployedHostArg.destinationPort
|
||||||
|
) {
|
||||||
|
hostCounter++;
|
||||||
|
foundHost = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!foundHost) {
|
||||||
|
unfoundHosts++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
this.deployedHosts.getArray().length !== this.hostCandidates.getArray().length ||
|
||||||
|
hostCounter !== this.deployedHosts.getArray().length ||
|
||||||
|
unfoundHosts !== 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deploy the current stack and restart nginx
|
||||||
|
*/
|
||||||
|
public async deploy() {
|
||||||
|
if (await this.areHostsDiverged()) {
|
||||||
|
this.logger.log('ok', `hosts have diverged, trigger config deployment and nginx reload!`);
|
||||||
|
this.deployedHosts.wipe();
|
||||||
|
this.deployedHosts.addArray(this.hostCandidates.getArray());
|
||||||
|
this.hostCandidates.wipe();
|
||||||
|
|
||||||
|
// write base config
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigDirPath);
|
||||||
|
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
|
||||||
|
|
||||||
|
// deploy hosts
|
||||||
|
plugins.smartfile.fs.ensureEmptyDirSync(paths.nginxHostDirPath);
|
||||||
|
for (const host of this.deployedHosts.getArray()) {
|
||||||
|
await host.deploy();
|
||||||
|
this.logger.log('info', `Host ${host.hostName} deployed!`);
|
||||||
|
}
|
||||||
|
this.nginxProcess.reloadConfig();
|
||||||
|
} else {
|
||||||
|
this.logger.log('info', `hosts have not diverged, skipping nginx reload`);
|
||||||
|
this.hostCandidates.wipe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,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;
|
|
||||||
};
|
|
@ -1,5 +1,9 @@
|
|||||||
import * as plugins from "./smartnginx.plugins"
|
import * as plugins from './smartnginx.plugins';
|
||||||
|
|
||||||
export let packageBase = plugins.path.join(__dirname,"../");
|
// directories
|
||||||
export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig/");
|
export const packageBase = plugins.path.join(__dirname, '../');
|
||||||
export let nginxZoneBase = plugins.path.join(nginxConfigBase,"zones");
|
export const nginxConfigDirPath = plugins.path.join(packageBase, 'nginxconfig');
|
||||||
|
export const nginxHostDirPath = plugins.path.join(nginxConfigDirPath, 'hosts');
|
||||||
|
|
||||||
|
// files
|
||||||
|
export const nginxConfFile = plugins.path.join(nginxConfigDirPath, 'nginx.conf');
|
@ -1,6 +1,15 @@
|
|||||||
import "typings-global";
|
// native
|
||||||
export import cert = require("cert");
|
import * as path from 'path';
|
||||||
export import path = require("path");
|
|
||||||
export import q = require("q");
|
export { path };
|
||||||
export let shelljs = require("shelljs");
|
|
||||||
export import smartfile = require("smartfile");
|
// @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';
|
||||||
|
import * as smartunique from '@pushrocks/smartunique';
|
||||||
|
|
||||||
|
export { lik, smartlog, smartpromise, smartshell, smartfile, smartstring, smartunique };
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
import * as plugins from './smartnginx.plugins';
|
||||||
|
import * as paths from './smartnginx.paths';
|
||||||
export let getBaseConfigString = () => {
|
export let getBaseConfigString = () => {
|
||||||
let baseConfig = `
|
const baseConfig = plugins.smartstring.indent.normalize(`
|
||||||
user www-data;
|
user www-data;
|
||||||
worker_processes auto;
|
worker_processes auto;
|
||||||
pid /run/nginx.pid;
|
pid /run/nginx/nginx.pid;
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections 768;
|
worker_connections 768;
|
||||||
@ -61,41 +63,35 @@ export let getBaseConfigString = () => {
|
|||||||
# Virtual Host Configs
|
# Virtual Host Configs
|
||||||
##
|
##
|
||||||
|
|
||||||
include /etc/nginx/conf.d/*.conf;
|
include ${paths.nginxHostDirPath}/*.conf;
|
||||||
include /etc/nginx/sites-enabled/*;
|
include /etc/nginx/sites-enabled/*;
|
||||||
}
|
}
|
||||||
daemon off;
|
daemon off;
|
||||||
`;
|
`);
|
||||||
}
|
return baseConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string, destinationPortArg = 80) => {
|
||||||
export let getZoneConfigString = (zoneNameArg:string,destinationIpArg:string) => {
|
const hostConfig = plugins.smartstring.indent.normalize(`
|
||||||
let zoneConfig = `
|
upstream ${hostNameArg} {
|
||||||
upstream ${zoneNameArg} {
|
keepalive 100;
|
||||||
server ${destinationIpArg};
|
server ${destinationIpArg}:${destinationPortArg};
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen *:80 ;
|
|
||||||
server_name ${zoneNameArg};
|
|
||||||
rewrite ^ https://${zoneNameArg}$request_uri? permanent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen *:443 ssl;
|
listen *:443 ssl;
|
||||||
server_name ${zoneNameArg};
|
server_name ${hostNameArg};
|
||||||
ssl_certificate /LE_CERTS/${zoneNameArg}/fullchain.pem;
|
ssl_certificate ${paths.nginxHostDirPath}/${hostNameArg}.public.pem;
|
||||||
ssl_certificate_key /LE_CERTS/${zoneNameArg}/privkey.pem;
|
ssl_certificate_key ${paths.nginxHostDirPath}/${hostNameArg}.private.pem;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://${zoneNameArg};
|
proxy_http_version 1.1;
|
||||||
include /etc/nginx/proxy_params;
|
proxy_buffering off;
|
||||||
}
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
location ~ /\.git {
|
proxy_set_header X-Forwarded-For $remote_addr;
|
||||||
deny all;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_pass http://${hostNameArg};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`);
|
||||||
return zoneConfig;
|
return hostConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
17
tslint.json
Normal file
17
tslint.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
|
}
|
Reference in New Issue
Block a user