Compare commits
120 Commits
Author | SHA1 | Date | |
---|---|---|---|
8c2aa23406 | |||
d2d4ad70ce | |||
e3817f92c7 | |||
159c043ba6 | |||
fbdb98c355 | |||
b81dc319e2 | |||
eec249d68f | |||
0f4a5b0cc1 | |||
20c23751a4 | |||
6aaae7683b | |||
826ae9f157 | |||
9dbeef0ed2 | |||
53f6daa5d5 | |||
9ee5cd2a3d | |||
13c27bb71e | |||
2be54dd505 | |||
2c5af1840e | |||
e5b75014af | |||
82f3b4bd7d | |||
4186e77ca0 | |||
6a05c0087f | |||
4206c9bc8a | |||
0aa6966dc1 | |||
5bbd773460 | |||
2c81f8b492 | |||
0fe7d586cf | |||
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 |
@ -1,35 +1,29 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
before_script:
|
||||
- "apt-get update && apt-get install nginx -y"
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm install
|
||||
- npmci npm test stable
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
environment: npmjs-com_registry
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci npm prepare
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Lossless GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
26
README.md
26
README.md
@ -1,20 +1,30 @@
|
||||
# smartnginx
|
||||
|
||||
control nginx from node, TypeScript ready
|
||||
|
||||
## Status
|
||||
|
||||
[](https://gitlab.com/pushrocks/smartnginx/commits/master)
|
||||
|
||||
## Features
|
||||
|
||||
- easy reverse configuration
|
||||
- automatic letsencrypt DNS01 challenge based ssl cert generation
|
||||
- automatic nginx process handling zero-downtime config reloading
|
||||
- works in Docker environements
|
||||
|
||||
## Usage
|
||||
|
||||
We recommend the use of TypeScript! :)
|
||||
|
||||
```typescript
|
||||
import * as smartnginx from "smartnginx";
|
||||
myNginxConfig = new smartnginx.NginxConfig();
|
||||
myNginxZone = new smartnginx.NginxZone({
|
||||
zoneName:"some.example.com",
|
||||
type:"reverseProxy",
|
||||
destination:"192.192.192.192" // some destination IP
|
||||
import * as smartnginx from 'smartnginx';
|
||||
const smartnginxInstance = new smartnginx.SmartNginx();
|
||||
myNginxHost = new smartnginx.NginxHost({
|
||||
hostName: 'some.example.com',
|
||||
type: 'reverseProxy',
|
||||
destination: '192.192.192.192' // some destination IP
|
||||
});
|
||||
myNginxConfig.addZone(myNginxZone); // adds the zone to the config
|
||||
myNginxConfig.deploy(); // deploys the referenced NginxConfig and restarts nginx
|
||||
```
|
||||
myNginxConfig.deploy(); // deploys the referenced NginxConfig and gracefully reloads it
|
||||
```
|
||||
|
4
dist/index.d.ts
vendored
4
dist/index.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
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;
|
11
dist/index.js
vendored
11
dist/index.js
vendored
@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
const CommandModule = require("./smartnginx.command");
|
||||
// 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQ0EsTUFBWSxhQUFhLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUV0RCxVQUFVO0FBQ1YsK0NBQTBCLGtDQUFrQyxDQUFDO0FBQXJELG1FQUFxRDtBQUM3RCw2Q0FBa0MsZ0NBQWdDLENBQUM7QUFBM0QsNkRBQVM7QUFBQyw2REFBaUQ7QUFFbkUsVUFBVTtBQUNDLGVBQU8sR0FBRyxhQUFhLENBQUMifQ==
|
14
dist/smartnginx.classes.nginxconfig.d.ts
vendored
14
dist/smartnginx.classes.nginxconfig.d.ts
vendored
@ -1,14 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import { NginxZone } from "./smartnginx.classes.nginxzone";
|
||||
export declare class NginxConfig {
|
||||
zones: NginxZone[];
|
||||
cert: plugins.cert.Cert;
|
||||
isDeployed: boolean;
|
||||
constructor(optionsArg: plugins.cert.ICertConstructorOptions);
|
||||
addZone(zoneArg: NginxZone): void;
|
||||
listZones(): NginxZone[];
|
||||
removeZones(zoneArg: NginxZone): void;
|
||||
clean(): void;
|
||||
deploy(nginxRestartArg?: boolean): plugins.q.Promise<{}>;
|
||||
}
|
68
dist/smartnginx.classes.nginxconfig.js
vendored
68
dist/smartnginx.classes.nginxconfig.js
vendored
@ -1,68 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
const paths = require("./smartnginx.paths");
|
||||
const command = require("./smartnginx.command");
|
||||
const snippets = require("./smartnginx.snippets");
|
||||
let allConfigs = [];
|
||||
class NginxConfig {
|
||||
constructor(optionsArg) {
|
||||
this.zones = [];
|
||||
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
|
||||
addZone(zoneArg) {
|
||||
this.zones.push(zoneArg);
|
||||
}
|
||||
listZones() {
|
||||
return this.zones;
|
||||
}
|
||||
;
|
||||
removeZones(zoneArg) {
|
||||
}
|
||||
clean() {
|
||||
this.zones = [];
|
||||
}
|
||||
// handle deployment of zones
|
||||
deploy(nginxRestartArg = false) {
|
||||
let done = plugins.q.defer();
|
||||
plugins.smartfile.fs.removeSync(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
|
||||
for (let config of allConfigs) {
|
||||
config.isDeployed = false;
|
||||
}
|
||||
;
|
||||
this.isDeployed = true;
|
||||
// write base config
|
||||
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), plugins.path.join(paths.nginxConfigBase, "nginx.conf"));
|
||||
// deploy zones
|
||||
let promiseArray = [];
|
||||
for (let zone of this.zones) {
|
||||
promiseArray.push(zone.deploy(this.cert));
|
||||
}
|
||||
;
|
||||
plugins.q.all(promiseArray)
|
||||
.then(() => {
|
||||
// restart nginx
|
||||
if (nginxRestartArg) {
|
||||
command.restart(this);
|
||||
}
|
||||
;
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.NginxConfig = NginxConfig;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELE1BQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsTUFBWSxPQUFPLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUNoRCxNQUFZLFFBQVEsV0FBTSx1QkFDMUIsQ0FBQyxDQURnRDtBQUVqRCxJQUFJLFVBQVUsR0FBaUIsRUFBRSxDQUFDO0FB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JBQ2hCLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDMUIsQ0FBQztZQUFBLENBQUM7WUFDRixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDbkIsQ0FBQyxDQUFDLENBQUM7UUFFUCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDOztBQUNMLENBQUM7QUEzRFksbUJBQVcsY0EyRHZCLENBQUE7QUFBQSxDQUFDIn0=
|
18
dist/smartnginx.classes.nginxzone.d.ts
vendored
18
dist/smartnginx.classes.nginxzone.d.ts
vendored
@ -1,18 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
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(certInstanceArg: plugins.cert.Cert): plugins.q.Promise<{}>;
|
||||
}
|
32
dist/smartnginx.classes.nginxzone.js
vendored
32
dist/smartnginx.classes.nginxzone.js
vendored
@ -1,32 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
const paths = require("./smartnginx.paths");
|
||||
const snippets = require("./smartnginx.snippets");
|
||||
(function (zoneTypes) {
|
||||
zoneTypes[zoneTypes["reverseProxy"] = 0] = "reverseProxy";
|
||||
zoneTypes[zoneTypes["static"] = 1] = "static";
|
||||
})(exports.zoneTypes || (exports.zoneTypes = {}));
|
||||
var zoneTypes = exports.zoneTypes;
|
||||
class NginxZone {
|
||||
constructor(optionsArg) {
|
||||
this.zoneName = optionsArg.zoneName;
|
||||
this.type = optionsArg.type;
|
||||
this.destination = optionsArg.destination;
|
||||
this.configString = snippets.getZoneConfigString(optionsArg.zoneName, optionsArg.destination);
|
||||
}
|
||||
;
|
||||
deploy(certInstanceArg) {
|
||||
let done = plugins.q.defer();
|
||||
let filePath = plugins.path.join(paths.nginxZoneBase, this.zoneName + ".conf");
|
||||
// writeConfig
|
||||
plugins.smartfile.memory.toFsSync(this.configString, filePath);
|
||||
// get cert
|
||||
certInstanceArg.getDomainCert(this.zoneName)
|
||||
.then(done.resolve);
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.NginxZone = NginxZone;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54em9uZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguY2xhc3Nlcy5uZ2lueHpvbmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDaEQsTUFBWSxLQUFLLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUU1QyxNQUFZLFFBQVEsV0FBTSx1QkFDMUIsQ0FBQyxDQURnRDtBQUNqRCxXQUFZLFNBQVM7SUFDZCx5REFBWSxDQUFBO0lBQ1osNkNBQU0sQ0FBQTtBQUNiLENBQUMsRUFIVyxpQkFBUyxLQUFULGlCQUFTLFFBR3BCO0FBSEQsSUFBWSxTQUFTLEdBQVQsaUJBR1gsQ0FBQTtBQUVEO0lBS0ksWUFBWSxVQUlYO1FBQ0csSUFBSSxDQUFDLFFBQVEsR0FBRyxVQUFVLENBQUMsUUFBUSxDQUFDO1FBQ3BDLElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBVSxDQUFDLElBQUksQ0FBQztRQUM1QixJQUFJLENBQUMsV0FBVyxHQUFHLFVBQVUsQ0FBQyxXQUFXLENBQUM7UUFDMUMsSUFBSSxDQUFDLFlBQVksR0FBRyxRQUFRLENBQUMsbUJBQW1CLENBQUMsVUFBVSxDQUFDLFFBQVEsRUFBQyxVQUFVLENBQUMsV0FBVyxDQUFDLENBQUM7SUFDakcsQ0FBQzs7SUFDRCxNQUFNLENBQUMsZUFBaUM7UUFDcEMsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUM3QixJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsYUFBYSxFQUFDLElBQUksQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFDLENBQUM7UUFDOUUsY0FBYztRQUNkLE9BQU8sQ0FBQyxTQUFTLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsWUFBWSxFQUFDLFFBQVEsQ0FBQyxDQUFDO1FBQzlELFdBQVc7UUFDWCxlQUFlLENBQUMsYUFBYSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUM7YUFDdkMsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUN4QixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDOztBQUNMLENBQUM7QUF6QlksaUJBQVMsWUF5QnJCLENBQUE7QUFBQSxDQUFDIn0=
|
19
dist/smartnginx.command.d.ts
vendored
19
dist/smartnginx.command.d.ts
vendored
@ -1,19 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
|
||||
/**
|
||||
* starts nginx
|
||||
*/
|
||||
export declare let start: (configArg: NginxConfig) => plugins.q.Promise<{}>;
|
||||
/**
|
||||
* restarts nginx
|
||||
*/
|
||||
export declare let restart: (configArg: NginxConfig) => plugins.q.Promise<{}>;
|
||||
/**
|
||||
* stops nginx
|
||||
*/
|
||||
export declare let stop: () => plugins.q.Promise<{}>;
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
export declare let check: () => boolean;
|
53
dist/smartnginx.command.js
vendored
53
dist/smartnginx.command.js
vendored
@ -1,53 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
let nginxChildProcess = undefined; // points to the nginx child process
|
||||
/**
|
||||
* starts nginx
|
||||
*/
|
||||
exports.start = (configArg) => {
|
||||
let done = plugins.q.defer();
|
||||
if (typeof nginxChildProcess == "undefined") {
|
||||
nginxChildProcess = plugins.childProcess.exec("nginx", function (error, stdout, stderr) {
|
||||
console.log(`stdout: ${stdout}`);
|
||||
console.log(`stderr: ${stderr}`);
|
||||
if (error !== null) {
|
||||
console.log(`exec error: ${error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
;
|
||||
plugins.beautylog.info("started Nginx!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
/**
|
||||
* restarts nginx
|
||||
*/
|
||||
exports.restart = (configArg) => {
|
||||
return exports.stop().then(() => {
|
||||
return exports.start(configArg);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* stops nginx
|
||||
*/
|
||||
exports.stop = () => {
|
||||
let done = plugins.q.defer();
|
||||
if (typeof nginxChildProcess != "undefined") {
|
||||
nginxChildProcess.kill();
|
||||
plugins.beautylog.info("stopped Nginx!");
|
||||
}
|
||||
else {
|
||||
plugins.beautylog.log("nginx already stopped!");
|
||||
}
|
||||
;
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
exports.check = () => {
|
||||
return;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jb21tYW5kLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jb21tYW5kLnRzIl0sIm5hbWVzIjpbXSwibWFwc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WUFBSSxFQUFFLENBQUMsSUFBSSxDQUNkO1FBQ0ksTUFBTSxDQUFDLGFBQUssQ0FBQyxTQUFTLENBQUMsQ0FBQztJQUM1QixDQUFDLENBQ0osQ0FBQztBQUNOLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ1EsWUFBSSxHQUFHO0lBQ2QsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixFQUFFLENBQUEsQ0FBQyxPQUFPLGlCQUFpQixJQUFJLFdBQVcsQ0FBQyxDQUFBLENBQUM7UUFDeEMsaUJBQWlCLENBQUMsSUFBSSxFQUFFLENBQUM7UUFDekIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztJQUM3QyxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyx3QkFBd0IsQ0FBQyxDQUFDO0lBQ3BELENBQUM7SUFBQSxDQUFDO0lBQ0YsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO0lBQ2YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDeEIsQ0FBQyxDQUFDO0FBRUY7O0dBRUc7QUFDUSxhQUFLLEdBQUc7SUFDZixNQUFNLENBQUM7QUFDWCxDQUFDLENBQUMifQ==
|
4
dist/smartnginx.paths.d.ts
vendored
4
dist/smartnginx.paths.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
export declare let packageBase: string;
|
||||
export declare let nginxConfigBase: string;
|
||||
export declare let nginxZoneBase: string;
|
||||
export declare let nginxCertBase: string;
|
7
dist/smartnginx.paths.js
vendored
7
dist/smartnginx.paths.js
vendored
@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
exports.packageBase = plugins.path.join(__dirname, "../");
|
||||
exports.nginxConfigBase = plugins.path.join(exports.packageBase, "nginxconfig");
|
||||
exports.nginxZoneBase = plugins.path.join(exports.nginxConfigBase, "zones");
|
||||
exports.nginxCertBase = plugins.path.join(exports.nginxConfigBase, "cert");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUV6QixDQUFDLENBRjhDO0FBRXBDLG1CQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFDO0FBQ2pELHVCQUFlLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsbUJBQVcsRUFBQyxhQUFhLENBQUMsQ0FBQztBQUMvRCxxQkFBYSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHVCQUFlLEVBQUMsT0FBTyxDQUFDLENBQUM7QUFDM0QscUJBQWEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyx1QkFBZSxFQUFDLE1BQU0sQ0FBQyxDQUFDIn0=
|
9
dist/smartnginx.plugins.d.ts
vendored
9
dist/smartnginx.plugins.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
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 import shelljs = require("shelljs");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartstring = require("smartstring");
|
11
dist/smartnginx.plugins.js
vendored
11
dist/smartnginx.plugins.js
vendored
@ -1,11 +0,0 @@
|
||||
"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixvQkFBWSxXQUFXLGVBQWUsQ0FBQyxDQUFDO0FBQ3hDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9
|
2
dist/smartnginx.snippets.d.ts
vendored
2
dist/smartnginx.snippets.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
export declare let getBaseConfigString: () => string;
|
||||
export declare let getZoneConfigString: (zoneNameArg: string, destinationIpArg: string) => string;
|
102
dist/smartnginx.snippets.js
vendored
102
dist/smartnginx.snippets.js
vendored
@ -1,102 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
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 /etc/nginx/conf.d/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
daemon off;
|
||||
`);
|
||||
return baseConfig;
|
||||
};
|
||||
exports.getZoneConfigString = (zoneNameArg, destinationIpArg) => {
|
||||
let zoneConfig = plugins.smartstring.indent.normalize(`
|
||||
upstream ${zoneNameArg} {
|
||||
server ${destinationIpArg};
|
||||
}
|
||||
|
||||
server {
|
||||
listen *:80 ;
|
||||
server_name ${zoneNameArg};
|
||||
rewrite ^ https://${zoneNameArg}$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;
|
||||
|
||||
location / {
|
||||
proxy_pass http://${zoneNameArg};
|
||||
include /etc/nginx/proxy_params;
|
||||
}
|
||||
location ~ /\.git {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
`);
|
||||
return zoneConfig;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5zbmlwcGV0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguc25pcHBldHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDckMsMkJBQW1CLEdBQUc7SUFDaEMsSUFBSSxVQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7RUFrRXJELENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDbkIsQ0FBQyxDQUFBO0FBR1UsMkJBQW1CLEdBQUcsQ0FBQyxXQUFrQixFQUFDLGdCQUF1QjtJQUMzRSxJQUFJLFVBQVUsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLE1BQU0sQ0FBQyxTQUFTLENBQUM7YUFDMUMsV0FBVztZQUNaLGdCQUFnQjs7Ozs7aUJBS1gsV0FBVzs4QkFDRSxXQUFXOzs7OztpQkFLeEIsV0FBVzsrQkFDRyxXQUFXO21DQUNQLFdBQVc7Ozt3QkFHdEIsV0FBVzs7Ozs7OztFQU9qQyxDQUFDLENBQUM7SUFDSCxNQUFNLENBQUMsVUFBVSxDQUFDO0FBQ25CLENBQUMsQ0FBQyJ9
|
8
npmextra.json
Normal file
8
npmextra.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"npmdocker": {
|
||||
|
||||
}
|
||||
}
|
1671
package-lock.json
generated
Normal file
1671
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
package.json
37
package.json
@ -1,12 +1,14 @@
|
||||
{
|
||||
"name": "smartnginx",
|
||||
"version": "0.0.7",
|
||||
"name": "@pushrocks/smartnginx",
|
||||
"version": "2.0.48",
|
||||
"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,19 +24,22 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
|
||||
"dependencies": {
|
||||
"@types/q": "^0.0.27",
|
||||
"@types/shelljs": "^0.3.27",
|
||||
"beautylog": "^5.0.14",
|
||||
"cert": "0.0.17",
|
||||
"q": "^1.4.1",
|
||||
"shelljs": "^0.7.0",
|
||||
"smartfile": "^4.0.12",
|
||||
"smartstring": "^2.0.15"
|
||||
"@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",
|
||||
"@pushrocks/smartunique": "^3.0.1",
|
||||
"selfsigned": "^1.10.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts-g": "^5.2.6",
|
||||
"qenv": "^1.0.8",
|
||||
"should": "^10.0.0",
|
||||
"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.15.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
}
|
||||
}
|
||||
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import "typings-test";
|
||||
import "should";
|
55
test/test.js
55
test/test.js
@ -1,55 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const path = require("path");
|
||||
require("should");
|
||||
const qenv_1 = require("qenv");
|
||||
const smartnginx = require("../dist/index");
|
||||
// setup environment
|
||||
let testQenv = new qenv_1.Qenv(process.cwd(), path.join(process.cwd(), ".nogit"));
|
||||
describe("smartnginx", function () {
|
||||
let testNginxConfig;
|
||||
let testNginxZone01;
|
||||
let testNginxZone02;
|
||||
describe("NginxZone", function () {
|
||||
it(`"new NginxZone()" should produce an instance of NginxConfig`, function () {
|
||||
testNginxZone01 = new smartnginx.NginxZone({
|
||||
zoneName: "test100.bleu.de",
|
||||
type: smartnginx.zoneTypes.reverseProxy,
|
||||
destination: "192.192.192.191"
|
||||
});
|
||||
testNginxZone02 = new smartnginx.NginxZone({
|
||||
zoneName: "test102.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({
|
||||
cfEmail: process.env.CF_EMAIL,
|
||||
cfKey: process.env.CF_KEY,
|
||||
testMode: true
|
||||
});
|
||||
testNginxConfig.should.be.instanceof(smartnginx.NginxConfig);
|
||||
});
|
||||
describe(".addZone()", function () {
|
||||
it("should add a zone to NginxConfig Object", function () {
|
||||
testNginxConfig.addZone(testNginxZone01);
|
||||
testNginxConfig.addZone(testNginxZone02);
|
||||
});
|
||||
});
|
||||
describe(".deploy()", function () {
|
||||
this.timeout(240000);
|
||||
it("should deploy a config from an instance", function (done) {
|
||||
testNginxConfig.deploy()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxJQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDOUIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQix1QkFBbUIsTUFBTSxDQUFDLENBQUE7QUFDMUIsTUFBWSxVQUFVLFdBQU0sZUFBZSxDQUFDLENBQUE7QUFFNUMsb0JBQW9CO0FBQ3BCLElBQUksUUFBUSxHQUFHLElBQUksV0FBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBQyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBQyxRQUFRLENBQUMsQ0FBQyxDQUFDO0FBQ3pFLFFBQVEsQ0FBQyxZQUFZLEVBQUM7SUFDbEIsSUFBSSxlQUFzQyxDQUFDO0lBQzNDLElBQUksZUFBb0MsQ0FBQztJQUN6QyxJQUFJ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BQyxVQUFVLENBQUMsV0FBVyxDQUFDLENBQUM7UUFDakUsQ0FBQyxDQUFDLENBQUM7UUFDSCxRQUFRLENBQUMsWUFBWSxFQUFDO1lBQ2xCLEVBQUUsQ0FBQyx5Q0FBeUMsRUFBQztnQkFDekMsZUFBZSxDQUFDLE9BQU8sQ0FBQyxlQUFlLENBQUMsQ0FBQztnQkFDekMsZUFBZSxDQUFDLE9BQU8sQ0FBQyxlQUFlLENBQUMsQ0FBQztZQUM3QyxDQUFDLENBQUMsQ0FBQTtRQUNOLENBQUMsQ0FBQyxDQUFDO1FBQ0gsUUFBUSxDQUFDLFdBQVcsRUFBQztZQUNqQixJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO1lBQ3JCLEVBQUUsQ0FBQyx5Q0FBeUMsRUFBQyxVQUFTLElBQUk7Z0JBQ3RELGVBQWUsQ0FBQyxNQUFNLEVBQUU7cUJBQ25CLElBQUksQ0FBQztvQkFDRixJQUFJLEVBQUUsQ0FBQztnQkFDWCxDQUFDLENBQUMsQ0FBQztZQUNYLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDLENBQUMsQ0FBQztBQUNQLENBQUMsQ0FBQyxDQUFDIn0=
|
105
test/test.ts
105
test/test.ts
@ -1,54 +1,55 @@
|
||||
import "typings-test";
|
||||
import path = require("path");
|
||||
import "should";
|
||||
import {Qenv} from "qenv";
|
||||
import * as smartnginx from "../dist/index";
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import path = require('path');
|
||||
|
||||
// setup environment
|
||||
let testQenv = new Qenv(process.cwd(),path.join(process.cwd(),".nogit"));
|
||||
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:"test100.bleu.de",
|
||||
type:smartnginx.zoneTypes.reverseProxy,
|
||||
destination:"192.192.192.191"
|
||||
});
|
||||
testNginxZone02 = new smartnginx.NginxZone({
|
||||
zoneName:"test102.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({
|
||||
cfEmail: process.env.CF_EMAIL,
|
||||
cfKey: process.env.CF_KEY,
|
||||
testMode:true
|
||||
});
|
||||
testNginxConfig.should.be.instanceof(smartnginx.NginxConfig);
|
||||
});
|
||||
describe(".addZone()",function(){
|
||||
it("should add a zone to NginxConfig Object",function(){
|
||||
testNginxConfig.addZone(testNginxZone01);
|
||||
testNginxConfig.addZone(testNginxZone02);
|
||||
})
|
||||
});
|
||||
describe(".deploy()",function(){
|
||||
this.timeout(240000);
|
||||
it("should deploy a config from an instance",function(done){
|
||||
testNginxConfig.deploy()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
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({defaultProxyUrl: 'https://git.zone'});
|
||||
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',
|
||||
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 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';
|
||||
|
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,67 +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[] = [];
|
||||
cert:plugins.cert.Cert; // the Cert Instance from which the config gets its certificates
|
||||
isDeployed:boolean = false;
|
||||
constructor(optionsArg:plugins.cert.ICertConstructorOptions){
|
||||
this.cert = new plugins.cert.Cert({
|
||||
cfEmail:optionsArg.cfEmail,
|
||||
cfKey:optionsArg.cfKey,
|
||||
sslDir:paths.nginxCertBase,
|
||||
gitOriginRepo:optionsArg.gitOriginRepo,
|
||||
testMode:optionsArg.testMode
|
||||
});
|
||||
};
|
||||
|
||||
// interact with Zones
|
||||
addZone(zoneArg:NginxZone){
|
||||
this.zones.push(zoneArg);
|
||||
}
|
||||
listZones():NginxZone[] {
|
||||
return this.zones;
|
||||
};
|
||||
removeZones(zoneArg:NginxZone){
|
||||
|
||||
}
|
||||
clean(){
|
||||
this.zones = [];
|
||||
}
|
||||
// handle deployment of zones
|
||||
deploy(nginxRestartArg:boolean = false){
|
||||
let done = plugins.q.defer();
|
||||
plugins.smartfile.fs.removeSync(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
|
||||
for(let config of allConfigs){
|
||||
config.isDeployed = false;
|
||||
};
|
||||
this.isDeployed = true;
|
||||
// write base config
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
snippets.getBaseConfigString(),
|
||||
plugins.path.join(paths.nginxConfigBase,"nginx.conf")
|
||||
);
|
||||
// deploy zones
|
||||
let promiseArray = [];
|
||||
for(let zone of this.zones){
|
||||
promiseArray.push(zone.deploy(this.cert));
|
||||
};
|
||||
plugins.q.all(promiseArray)
|
||||
.then(() => {
|
||||
// restart nginx
|
||||
if(nginxRestartArg){
|
||||
command.restart(this);
|
||||
};
|
||||
done.resolve();
|
||||
});
|
||||
|
||||
return done.promise;
|
||||
};
|
||||
};
|
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,35 +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(certInstanceArg:plugins.cert.Cert){
|
||||
let done = plugins.q.defer();
|
||||
let filePath = plugins.path.join(paths.nginxZoneBase,this.zoneName + ".conf");
|
||||
// writeConfig
|
||||
plugins.smartfile.memory.toFsSync(this.configString,filePath);
|
||||
// get cert
|
||||
certInstanceArg.getDomainCert(this.zoneName)
|
||||
.then(done.resolve);
|
||||
return done.promise;
|
||||
};
|
||||
};
|
137
ts/smartnginx.classes.smartnginx.ts
Normal file
137
ts/smartnginx.classes.smartnginx.ts
Normal file
@ -0,0 +1,137 @@
|
||||
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';
|
||||
|
||||
export interface ISmartNginxContructorOptions {
|
||||
logger?: plugins.smartlog.Smartlog;
|
||||
defaultProxyUrl: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* main class that manages a NginxInstance
|
||||
*/
|
||||
export class SmartNginx {
|
||||
public options: ISmartNginxContructorOptions;
|
||||
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: ISmartNginxContructorOptions) {
|
||||
this.options = optionsArg;
|
||||
this.options.logger
|
||||
? (this.logger = this.options.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(this.options.defaultProxyUrl), paths.nginxConfFile);
|
||||
|
||||
// write standard self signed certificate
|
||||
const selfsignedCert = plugins.selfsigned.generate([{ name: 'commonName', value: 'selfsigned.git.zone' }], { days: 365});
|
||||
|
||||
// deploy hosts
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxHostDirPath);
|
||||
plugins.smartfile.memory.toFsSync(selfsignedCert.private, plugins.path.join(paths.nginxHostDirPath, './default.private.pem'));
|
||||
plugins.smartfile.memory.toFsSync(selfsignedCert.cert, plugins.path.join(paths.nginxHostDirPath, './default.public.pem'));
|
||||
for (const host of this.deployedHosts.getArray()) {
|
||||
await host.deploy();
|
||||
this.logger.log('info', `Host ${host.hostName} deployed!`);
|
||||
}
|
||||
this.nginxProcess.reloadConfig();
|
||||
} else {
|
||||
this.logger.log('info', `hosts have not diverged, skipping nginx reload`);
|
||||
this.hostCandidates.wipe();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import {NginxConfig} from "./smartnginx.classes.nginxconfig";
|
||||
import {NginxZone} from "./smartnginx.classes.nginxzone";
|
||||
|
||||
|
||||
let nginxChildProcess = undefined; // points to the nginx child process
|
||||
|
||||
|
||||
/**
|
||||
* starts nginx
|
||||
*/
|
||||
export let start = (configArg:NginxConfig) => {
|
||||
let done = plugins.q.defer();
|
||||
if(typeof nginxChildProcess == "undefined"){
|
||||
nginxChildProcess = plugins.childProcess.exec("nginx",function(error, stdout, stderr){
|
||||
console.log(`stdout: ${stdout}`);
|
||||
console.log(`stderr: ${stderr}`);
|
||||
if (error !== null) {
|
||||
console.log(`exec error: ${error}`);
|
||||
}
|
||||
});
|
||||
};
|
||||
plugins.beautylog.info("started Nginx!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* restarts nginx
|
||||
*/
|
||||
export let restart = (configArg:NginxConfig) => {
|
||||
return stop().then(
|
||||
() => {
|
||||
return start(configArg);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* stops nginx
|
||||
*/
|
||||
export let stop = () => {
|
||||
let done = plugins.q.defer();
|
||||
if(typeof nginxChildProcess != "undefined"){
|
||||
nginxChildProcess.kill();
|
||||
plugins.beautylog.info("stopped Nginx!");
|
||||
} else {
|
||||
plugins.beautylog.log("nginx already stopped!");
|
||||
};
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
export let check = ():boolean => {
|
||||
return;
|
||||
};
|
@ -1,6 +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");
|
||||
export let nginxCertBase = plugins.path.join(nginxConfigBase,"cert");
|
||||
// directories
|
||||
export const packageBase = plugins.path.join(__dirname, '../');
|
||||
export const nginxConfigDirPath = plugins.path.join(packageBase, 'nginxconfig');
|
||||
export const nginxHostDirPath = plugins.path.join(nginxConfigDirPath, 'hosts');
|
||||
|
||||
// files
|
||||
export const nginxConfFile = plugins.path.join(nginxConfigDirPath, 'nginx.conf');
|
@ -1,9 +1,22 @@
|
||||
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 import 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';
|
||||
import * as smartunique from '@pushrocks/smartunique';
|
||||
|
||||
export { lik, smartlog, smartpromise, smartshell, smartfile, smartstring, smartunique };
|
||||
|
||||
// thirdparty scope
|
||||
import * as selfsigned from 'selfsigned';
|
||||
|
||||
export {
|
||||
selfsigned
|
||||
};
|
||||
|
@ -1,9 +1,10 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
export let getBaseConfigString = () => {
|
||||
let baseConfig = plugins.smartstring.indent.normalize(`
|
||||
import * as plugins from './smartnginx.plugins';
|
||||
import * as paths from './smartnginx.paths';
|
||||
export let getBaseConfigString = (defaultProxy: string) => {
|
||||
const 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,61 @@ export let getBaseConfigString = () => {
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
server {
|
||||
listen *:80 default_server;
|
||||
server_name selfsigned.git.zone;
|
||||
rewrite ^ ${defaultProxy} redirect;
|
||||
}
|
||||
|
||||
server {
|
||||
listen *:443 ssl default_server;
|
||||
server_name selfsigned.git.zone;
|
||||
ssl_certificate ${paths.nginxHostDirPath}/default.public.pem;
|
||||
ssl_certificate_key ${paths.nginxHostDirPath}/default.private.pem;
|
||||
rewrite ^ ${defaultProxy} redirect;
|
||||
}
|
||||
|
||||
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} {
|
||||
server ${destinationIpArg};
|
||||
export let getHostConfigString = (hostNameArg: string, destinationIpArg: string, destinationPortArg = 80) => {
|
||||
const hostConfig = plugins.smartstring.indent.normalize(`
|
||||
upstream ${hostNameArg} {
|
||||
keepalive 100;
|
||||
server ${destinationIpArg}:${destinationPortArg};
|
||||
}
|
||||
|
||||
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_buffering off;
|
||||
proxy_redirect off;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_next_upstream error timeout http_404 http_429 http_500 http_502;
|
||||
proxy_next_upstream_tries 5;
|
||||
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