Compare commits

...

122 Commits

Author SHA1 Message Date
8a35725448 2.0.50 2019-08-20 22:30:32 +02:00
5438f83a40 fix(core): update 2019-08-20 22:30:31 +02:00
5c4d5a4a85 2.0.49 2019-08-20 22:28:48 +02:00
1be3f7f388 fix(core): update 2019-08-20 22:28:48 +02:00
8c2aa23406 2.0.48 2019-08-14 13:06:05 +02:00
d2d4ad70ce fix(core): update 2019-08-14 13:06:04 +02:00
e3817f92c7 2.0.47 2019-04-11 02:01:45 +02:00
159c043ba6 fix(core): update 2019-04-11 02:01:44 +02:00
fbdb98c355 2.0.46 2019-04-11 01:42:49 +02:00
b81dc319e2 fix(core): update 2019-04-11 01:42:48 +02:00
eec249d68f 2.0.45 2019-04-11 01:32:08 +02:00
0f4a5b0cc1 fix(core): update 2019-04-11 01:32:08 +02:00
20c23751a4 2.0.44 2019-04-11 00:40:34 +02:00
6aaae7683b fix(core): update 2019-04-11 00:40:33 +02:00
826ae9f157 2.0.43 2019-04-11 00:15:06 +02:00
9dbeef0ed2 fix(core): update 2019-04-11 00:15:06 +02:00
53f6daa5d5 2.0.42 2019-04-10 23:15:37 +02:00
9ee5cd2a3d fix(core): update 2019-04-10 23:15:37 +02:00
13c27bb71e 2.0.41 2019-04-10 23:14:08 +02:00
2be54dd505 fix(core): update 2019-04-10 23:14:08 +02:00
2c5af1840e 2.0.40 2019-04-10 19:03:17 +02:00
e5b75014af fix(core): update 2019-04-10 19:03:17 +02:00
82f3b4bd7d 2.0.39 2019-02-02 12:10:00 +01:00
4186e77ca0 fix(core): cleanup 2019-02-02 12:09:59 +01:00
6a05c0087f 2.0.38 2019-01-25 12:37:13 +01:00
4206c9bc8a fix(core): update 2019-01-25 12:37:12 +01:00
0aa6966dc1 2.0.37 2019-01-22 22:42:54 +01:00
5bbd773460 fix(core): update 2019-01-22 22:42:54 +01:00
2c81f8b492 2.0.36 2019-01-22 22:07:59 +01:00
0fe7d586cf fix(core): update 2019-01-22 22:07:58 +01:00
a4c8b789ad 2.0.35 2019-01-22 22:05:03 +01:00
b4378e305a fix(core): update 2019-01-22 22:05:02 +01:00
5ff0980908 2.0.34 2019-01-22 18:59:56 +01:00
e60257d761 fix(core): update 2019-01-22 18:59:55 +01:00
e94f0edafb 2.0.33 2019-01-22 18:25:44 +01:00
c417d96e48 fix(core): update 2019-01-22 18:25:43 +01:00
c5b1dbb46e 2.0.32 2019-01-22 12:33:48 +01:00
893a2e2709 fix(core): update 2019-01-22 12:33:47 +01:00
01f0dc6b20 2.0.31 2019-01-22 12:11:32 +01:00
736a42066c fix(core): update 2019-01-22 12:11:31 +01:00
44403863d1 2.0.30 2019-01-22 12:03:00 +01:00
5be21fa100 fix(core): update 2019-01-22 12:02:59 +01:00
042167c01e 2.0.29 2019-01-22 04:03:17 +01:00
db38d038ef fix(core): update 2019-01-22 04:03:17 +01:00
a4d8a46360 2.0.28 2019-01-19 15:57:50 +01:00
84e5c10129 fix(core): update 2019-01-19 15:57:49 +01:00
98a2871f08 2.0.27 2019-01-19 15:42:46 +01:00
9bb847210a fix(core): update 2019-01-19 15:42:45 +01:00
91d4ba5715 2.0.26 2019-01-19 15:41:51 +01:00
3ee2988964 fix(core): update 2019-01-19 15:41:51 +01:00
221f1f6237 2.0.25 2019-01-19 12:17:47 +01:00
0a6fbf588e fix(core): update 2019-01-19 12:17:47 +01:00
1a8546af6e 2.0.24 2019-01-19 11:07:14 +01:00
9e01bdb8e2 fix(core): update 2019-01-19 11:07:14 +01:00
33833fbc6c 2.0.23 2019-01-19 10:59:25 +01:00
97b5678fe4 fix(core): update 2019-01-19 10:59:24 +01:00
9b96984413 2.0.22 2019-01-19 03:21:27 +01:00
0de412b842 fix(core): update 2019-01-19 03:21:27 +01:00
64bcce9e23 2.0.21 2019-01-19 03:04:38 +01:00
390812ec33 fix(core): update 2019-01-19 03:04:38 +01:00
a672bb920f 2.0.20 2019-01-19 02:46:41 +01:00
c3fabb6107 fix(core): update 2019-01-19 02:46:41 +01:00
b4ebdbae47 2.0.19 2019-01-19 02:44:52 +01:00
c55d2dcf10 fix(core): update 2019-01-19 02:44:52 +01:00
7274d5ea8a 2.0.18 2019-01-19 02:25:35 +01:00
1ec733c2a9 fix(core): update 2019-01-19 02:25:34 +01:00
3ef14d8ac7 2.0.17 2019-01-18 01:33:02 +01:00
f332bf95fe fix(core): update 2019-01-18 01:33:01 +01:00
6acad8a306 2.0.16 2019-01-18 00:46:09 +01:00
6ae672f707 fix(core): update 2019-01-18 00:46:08 +01:00
3d263e2181 2.0.15 2019-01-18 00:45:29 +01:00
85639f29af fix(core): update 2019-01-18 00:45:29 +01:00
85448a21fc 2.0.14 2019-01-17 13:39:16 +01:00
3b85c4a37e fix(core): update 2019-01-17 13:39:15 +01:00
67dd650dce 2.0.13 2019-01-17 02:50:32 +01:00
92eaf5f19a fix(core): update 2019-01-17 02:50:32 +01:00
fcf9a61b1d 2.0.12 2019-01-09 14:13:32 +01:00
fbd258a876 fix(core): update 2019-01-09 14:13:32 +01:00
c65b8fc1af 2.0.11 2019-01-09 14:10:57 +01:00
b7b588d713 fix(core): update 2019-01-09 14:10:57 +01:00
00d672c135 2.0.10 2019-01-09 12:18:56 +01:00
6a1e778b49 fix(core): update 2019-01-09 12:18:56 +01:00
4cfb26f62f 2.0.9 2019-01-09 12:18:07 +01:00
7ba3ad0b21 fix(core): update 2019-01-09 12:18:06 +01:00
cd93ec2560 2.0.8 2019-01-09 12:15:29 +01:00
ede884930e fix(core): update 2019-01-09 12:15:28 +01:00
1049920efd 2.0.7 2019-01-01 22:35:18 +01:00
b7a34403c5 fix(core): update 2019-01-01 22:35:18 +01:00
987e19372a 2.0.6 2019-01-01 22:34:37 +01:00
0b97aaee91 fix(core): update 2019-01-01 22:34:36 +01:00
b87ca1fa03 2.0.5 2018-08-11 15:10:28 +02:00
824f872fa5 fix(tests): update 2018-08-11 15:10:27 +02:00
80248c77d0 2.0.4 2018-08-11 15:09:19 +02:00
f592150646 fix(host handling): update 2018-08-11 15:09:19 +02:00
f24652936a 2.0.3 2018-08-11 00:29:16 +02:00
79af6c4a68 fix(CI): accessLevel 2018-08-11 00:29:16 +02:00
fafc757930 2.0.2 2018-08-11 00:25:20 +02:00
ead5e1a7bd fix(CI): now installing stufall alright 2018-08-11 00:25:20 +02:00
ad57be180a 2.0.1 2018-08-10 23:44:31 +02:00
7cc4ce02c9 fix(core): update 2018-08-10 23:44:31 +02:00
70dace595b 2.0.0 2018-08-10 23:10:48 +02:00
9b043d0e0d BREAKING CHANGE(scope): change scope to @pushrocks 2018-08-10 23:10:48 +02:00
381227406b 1.0.6 2016-08-03 14:10:09 +02:00
08d1c292c3 update dependencies 2016-08-03 14:10:03 +02:00
64b0a2deb7 1.0.5 2016-08-03 12:05:18 +02:00
9b661c0ee5 update types versions 2016-08-03 12:05:03 +02:00
8ca91a48e8 1.0.4 2016-08-02 23:58:47 +02:00
39a5683b9e improve snippets 2016-08-02 23:58:00 +02:00
7967334e7d 1.0.3 2016-08-02 23:50:48 +02:00
5a875d1e22 Merge branch 'master' of gitlab.com:pushrocks/smartnginx 2016-08-02 23:48:30 +02:00
4c68d27b6d 1.0.2 2016-08-02 23:47:33 +02:00
1cca4f95bc fix interface name 2016-08-02 23:47:27 +02:00
3cef614bb3 1.0.1 2016-08-02 15:32:10 +02:00
c3c2ab776d consolidate naming and start exporting interfaces 2016-08-02 15:32:06 +02:00
a533fa5de1 Add license 2016-07-25 01:53:33 +00:00
d8a4c3d088 1.0.0 2016-07-25 03:21:33 +02:00
e2639fd0a9 now talking correctly to nginx 2016-07-25 03:21:28 +02:00
b5a27d5108 0.1.0 2016-07-25 02:57:38 +02:00
f32002309d now ending nginx after test 2016-07-25 02:57:17 +02:00
52c3b40879 improve README 2016-07-25 02:02:24 +02:00
6de1352f5f 0.0.9 2016-07-25 01:57:55 +02:00
c55977d5e4 fix tests 2016-07-25 01:57:51 +02:00
48 changed files with 2522 additions and 760 deletions

25
.gitignore vendored
View File

@ -1,5 +1,22 @@
node_modules/
nginxconfig/
.nogit/
# artifacts
coverage/
docs/
.nogit/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,40 +1,119 @@
image: hosttoday/ht-docker-node:npmts
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- metadata
before_script:
- "apt-get update && apt-get install nginx -y"
testLEGACY:
stage: test
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci test legacy
- npmci git mirror
tags:
- docker
allow_failure: true
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLTS:
stage: test
script:
- npmci test lts
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testSTABLE:
- docker
- priv
testBuild:
stage: test
script:
- npmci test stable
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- docker
- notpriv
release:
stage: release
environment: npmjs-com_registry
script:
- npmci publish
- npmci node install lts
- npmci npm publish
only:
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:18-dind
stage: metadata
script:
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- docker
- notpriv
only:
- tags
tags:
- docker
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Lossless GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,20 +1,40 @@
# smartnginx
# @pushrocks/smartnginx
control nginx from node, TypeScript ready
## Status
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartnginx)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartnginx)
* [github.com (source mirror)](https://github.com/pushrocks/smartnginx)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnginx/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartnginx/badges/master/build.svg)](https://gitlab.com/pushrocks/smartnginx/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartnginx/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartnginx/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartnginx.svg)](https://www.npmjs.com/package/@pushrocks/smartnginx)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartnginx/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartnginx)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## 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
```
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

3
dist/index.d.ts vendored
View File

@ -1,3 +0,0 @@
export { NginxConfig } from "./smartnginx.classes.nginxconfig";
export { NginxProcess } from "./smartnginx.classes.nginxprocess";
export { NginxZone, zoneTypes } from "./smartnginx.classes.nginxzone";

10
dist/index.js vendored
View File

@ -1,10 +0,0 @@
"use strict";
// classes
var smartnginx_classes_nginxconfig_1 = require("./smartnginx.classes.nginxconfig");
exports.NginxConfig = smartnginx_classes_nginxconfig_1.NginxConfig;
var smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
exports.NginxProcess = smartnginx_classes_nginxprocess_1.NginxProcess;
var smartnginx_classes_nginxzone_1 = require("./smartnginx.classes.nginxzone");
exports.NginxZone = smartnginx_classes_nginxzone_1.NginxZone;
exports.zoneTypes = smartnginx_classes_nginxzone_1.zoneTypes;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBRUEsVUFBVTtBQUNWLCtDQUEwQixrQ0FBa0MsQ0FBQztBQUFyRCxtRUFBcUQ7QUFDN0QsZ0RBQTJCLG1DQUFtQyxDQUFDO0FBQXZELHNFQUF1RDtBQUMvRCw2Q0FBa0MsZ0NBQWdDLENBQUM7QUFBM0QsNkRBQVM7QUFBQyw2REFBaUQifQ==

View File

@ -1,16 +0,0 @@
/// <reference types="q" />
import * as plugins from "./smartnginx.plugins";
import { NginxZone } from "./smartnginx.classes.nginxzone";
import { NginxProcess } from "./smartnginx.classes.nginxprocess";
export declare class NginxConfig {
zones: NginxZone[];
cert: plugins.cert.Cert;
nginxProcess: NginxProcess;
isDeployed: boolean;
constructor(optionsArg: plugins.cert.ICertConstructorOptions);
addZone(zoneArg: NginxZone): void;
listZones(): NginxZone[];
removeZones(zoneArg: NginxZone): void;
clean(): void;
deploy(): plugins.q.Promise<{}>;
}

View File

@ -1,68 +0,0 @@
"use strict";
const plugins = require("./smartnginx.plugins");
const paths = require("./smartnginx.paths");
const snippets = require("./smartnginx.snippets");
const smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
let allConfigs = [];
class NginxConfig {
constructor(optionsArg) {
this.zones = [];
this.nginxProcess = new smartnginx_classes_nginxprocess_1.NginxProcess(this);
this.isDeployed = false;
this.cert = new plugins.cert.Cert({
cfEmail: optionsArg.cfEmail,
cfKey: optionsArg.cfKey,
sslDir: paths.nginxCertBase,
gitOriginRepo: optionsArg.gitOriginRepo,
testMode: optionsArg.testMode
});
}
;
// interact with Zones
addZone(zoneArg) {
this.zones.push(zoneArg);
}
listZones() {
return this.zones;
}
;
removeZones(zoneArg) {
}
clean() {
this.zones = [];
}
// handle deployment of zones
deploy() {
let done = plugins.q.defer();
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(), paths.nginxConfFile);
// deploy zones
let promiseArray = [];
for (let zone of this.zones) {
let zoneDeployedPromise = zone.deploy(this.cert);
zoneDeployedPromise.then(() => {
plugins.beautylog.info(`Zone ${zone.zoneName} deployed!`);
this.nginxProcess.reloadConfig();
});
promiseArray.push(zoneDeployedPromise);
}
;
plugins.q.all(promiseArray)
.then(() => {
done.resolve();
});
return done.promise;
}
;
}
exports.NginxConfig = NginxConfig;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELE1BQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsTUFBWSxRQUFRLFdBQU0sdUJBQXVCLENBQUMsQ0FBQTtBQUVsRCxrREFBNkIsbUNBQW1DLENBQUMsQ0FBQTtBQUNqRSxJQUFJLFVBQVUsR0FBa0IsRUFBRSxDQUFDO0FBRW5DO0lBS0ksWUFBWSxVQUFnRDtRQUo1RCxVQUFLLEdBQWdCLEVBQUUsQ0FBQztRQUV4QixpQkFBWSxHQUFpQixJQUFJLDhDQUFZLENBQUMsSUFBSSxDQUFDLENB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FNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDOztBQUNMLENBQUM7QUE1RFksbUJBQVcsY0E0RHZCLENBQUE7QUFBQSxDQUFDIn0=

View File

@ -1,26 +0,0 @@
/// <reference types="node" />
/// <reference types="q" />
import * as plugins from "./smartnginx.plugins";
import { NginxConfig } from "./smartnginx.classes.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;
}

View File

@ -1,75 +0,0 @@
"use strict";
const plugins = require("./smartnginx.plugins");
const paths = require("./smartnginx.paths");
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 {
this.nginxChildProcess.kill("SIGHUP");
}
;
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") {
this.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
*/
check()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FPLElBQUksQ0FBQyxpQkFBaUIsSUFBSSxXQUFXLENBQUMsQ0FBQyxDQUFDO1lBQy9DLElBQUksQ0FBQyxpQkFBaUIsQ0FBQyxJQUFJLEVBQUUsQ0FBQztZQUM5QixPQUFPLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDO1FBQzdDLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNKLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUM7UUFDcEQsQ0FBQztRQUFBLENBQUM7UUFDRixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDZixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDOztJQUVEOztPQUVHO0lBQ0gsS0FBSztRQUNELE1BQU0sQ0FBQztJQUNYLENBQUM7O0FBQ0wsQ0FBQztBQWhFWSxvQkFBWSxlQWdFeEIsQ0FBQSJ9

View File

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

View File

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

View File

@ -1,5 +0,0 @@
export declare let packageBase: string;
export declare let nginxConfigBase: string;
export declare let nginxZoneBase: string;
export declare let nginxCertBase: string;
export declare let nginxConfFile: string;

View File

@ -1,10 +0,0 @@
"use strict";
const plugins = require("./smartnginx.plugins");
// directories
exports.packageBase = plugins.path.join(__dirname, "../");
exports.nginxConfigBase = plugins.path.join(exports.packageBase, "nginxconfig");
exports.nginxZoneBase = plugins.path.join(exports.nginxConfigBase, "zones");
exports.nginxCertBase = plugins.path.join(exports.nginxConfigBase, "cert");
// files
exports.nginxConfFile = plugins.path.join(exports.nginxConfigBase, "nginx.conf");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUd6QixDQUFDLENBSDhDO0FBRS9DLGNBQWM7QUFDSCxtQkFBVyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxLQUFLLENBQUMsQ0FBQztBQUNqRCx1QkFBZSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLG1CQUFXLEVBQUMsYUFBYSxDQUFDLENBQUM7QUFDL0QscUJBQWEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyx1QkFBZSxFQUFDLE9BQU8sQ0FBQyxDQUFDO0FBQzNELHFCQUFhLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsdUJBQWUsRUFBQyxNQUFNLENBQUMsQ0FBQztBQUVyRSxRQUFRO0FBQ0cscUJBQWEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyx1QkFBZSxFQUFDLFlBQVksQ0FBQyxDQUFDIn0=

View File

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

View File

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

View File

@ -1,2 +0,0 @@
export declare let getBaseConfigString: () => string;
export declare let getZoneConfigString: (zoneNameArg: string, destinationIpArg: string) => string;

View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5zbmlwcGV0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguc25pcHBldHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDckMsMkJBQW1CLEdBQUc7SUFDaEMsSUFBSSxVQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7RUFrRXJELENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDbkIsQ0FBQyxDQUFBO0FBR1UsMkJBQW1CLEdBQUcsQ0FBQyxXQUFrQixFQUFDLGdCQUF1QjtJQUMzRSxJQUFJLFVBQVUsR0FBRyxPQUFP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CQ6nT++ObmCoIQzLtsjJlJ10UBRF5GsgZBCmhsp0T6J9YQsv
AOSzUX4GL98tSol2OakCQDpb11GrMuDVfYW+ltJs/WFOIE/Qexy+pKU6uWQnGjGP
3OQVJ68vPebrMqQ6Lp3/r5hbN/UgLMufrUuevtHb7DA=
-----END RSA PRIVATE KEY-----

View File

@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE-----
MIIB/zCCAWigAwIBAgIJeD6pc7FCt9rnMA0GCSqGSIb3DQEBBQUAMB4xHDAaBgNV
BAMTE3NlbGZzaWduZWQuZ2l0LnpvbmUwHhcNMTkwODIwMjAzMDI1WhcNMjAwODE5
MjAzMDI1WjAeMRwwGgYDVQQDExNzZWxmc2lnbmVkLmdpdC56b25lMIGfMA0GCSqG
SIb3DQEBAQUAA4GNADCBiQKBgQCMGIi2uxtbfbDIiyL6SWwZb1RdSpjGFHwzlR+m
ipbwgW1JsYldFs463PvxsMFgyQ6Nzndj3IE1mpYQgWYSS69mV8B3XxusrxnOGeO0
0IdA+qPGakzqSm+/2ualnz6nDeVWTvQuM15Ki6WQsbvmcIKngs+5tsmYfTiAnpFU
v3t6zQIDAQABo0UwQzAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIC9DAmBgNVHREE
HzAdhhtodHRwOi8vZXhhbXBsZS5vcmcvd2ViaWQjbWUwDQYJKoZIhvcNAQEFBQAD
gYEARLQhxnvrKNGs758MzDTbf3lBuMd5jf42YFcUdEPI6jg9knKwqcgd5eNkZtNM
DFPOFJf3HIJOLeOhXZ4bzQpcxVkkDAMUloKmQNypZlRWzkZt0jLgG0/ofKvvqX7c
DpzwgTIoJwWlpbug788LEm3HcTVPu0LxQ1lOpgt0PWPnasc=
-----END CERTIFICATE-----

View File

@ -0,0 +1,31 @@
upstream test100.bleu.de {
keepalive 100;
server 192.192.192.191:3000;
}
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 test100.bleu.de;
rewrite ^ https://test100.bleu.de$request_uri? permanent;
}
server {
listen *:443 ssl;
server_name test100.bleu.de;
ssl_certificate /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/test100.bleu.de.public.pem;
ssl_certificate_key /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/test100.bleu.de.private.pem;
location / {
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://test100.bleu.de;
}
}

View File

@ -0,0 +1 @@
some private

View File

@ -0,0 +1 @@
some public

View File

@ -0,0 +1,31 @@
upstream test102.bleu.de {
keepalive 100;
server 192.192.192.192:3050;
}
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 test102.bleu.de;
rewrite ^ https://test102.bleu.de$request_uri? permanent;
}
server {
listen *:443 ssl;
server_name test102.bleu.de;
ssl_certificate /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/test102.bleu.de.public.pem;
ssl_certificate_key /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/test102.bleu.de.private.pem;
location / {
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://test102.bleu.de;
}
}

View File

@ -0,0 +1 @@
some private

View File

@ -0,0 +1 @@
some public

79
nginxconfig/nginx.conf Normal file
View File

@ -0,0 +1,79 @@
user www-data;
worker_processes auto;
pid /run/nginx/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
##
server {
listen *:80 default_server;
server_name selfsigned.git.zone;
rewrite ^ https://git.zone redirect;
}
server {
listen *:443 ssl default_server;
server_name selfsigned.git.zone;
ssl_certificate /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/default.public.pem;
ssl_certificate_key /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/default.private.pem;
rewrite ^ https://git.zone redirect;
}
include /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/*.conf;
include /etc/nginx/sites-enabled/*;
}
daemon off;

16
npmextra.json Normal file
View File

@ -0,0 +1,16 @@
{
"npmci": {
"npmAccessLevel": "public"
},
"npmdocker": {},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartnginx",
"shortDescription": "control nginx from node, TypeScript ready",
"npmPackagename": "@pushrocks/smartnginx",
"license": "MIT"
}
}
}

1671
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,14 @@
{
"name": "smartnginx",
"version": "0.0.8",
"name": "@pushrocks/smartnginx",
"version": "2.0.50",
"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,33 @@
},
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
"dependencies": {
"@types/q": "^0.0.27",
"@types/shelljs": "^0.3.27",
"beautylog": "^5.0.18",
"cert": "1.0.6",
"q": "^1.4.1",
"shelljs": "^0.7.1",
"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"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

View File

@ -1,3 +1 @@
vars:
- CF_EMAIL
- CF_KEY
required:

2
test/test.d.ts vendored
View File

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

View File

@ -1,56 +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 () {
this.timeout(10000);
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(600000);
it("should deploy a config from an instance", function (done) {
testNginxConfig.deploy()
.then(() => {
done();
});
});
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxJQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDOUIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQix1QkFBbUIsTUFBTSxDQUFDLENBQUE7QUFDMUIsTUFBWSxVQUFVLFdBQU0sZUFBZSxDQUFDLENBQUE7QUFFNUMsb0JBQW9CO0FBQ3BCLElBQUksUUFBUSxHQUFHLElBQUksV0FBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUF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VUFBVSxDQUFDLFdBQVcsQ0FBQztnQkFDekMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsUUFBUTtnQkFDN0IsS0FBSyxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsTUFBTTtnQkFDekIsUUFBUSxFQUFDLElBQUk7YUFDaEIsQ0FBQyxDQUFDO1lBQ0gsZUFBZSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFVBQVUsQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUNqRSxDQUFDLENBQUMsQ0FBQztRQUNILFFBQVEsQ0FBQyxZQUFZLEVBQUM7WUFDbEIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDO2dCQUN6QyxlQUFlLENBQUMsT0FBTyxDQUFDLGVBQWUsQ0FBQyxDQUFDO2dCQUN6QyxlQUFlLENBQUMsT0FBTyxDQUFDLGVBQWUsQ0FBQyxDQUFDO1lBQzdDLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQyxDQUFDLENBQUM7UUFDSCxRQUFRLENBQUMsV0FBVyxFQUFDO1lBQ2pCLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7WUFDckIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDLFVBQVMsSUFBSTtnQkFDdEQsZUFBZSxDQUFDLE1BQU0sRUFBRTtxQkFDbkIsSUFBSSxDQUFDO29CQUNGLElBQUksRUFBRSxDQUFDO2dCQUNYLENBQUMsQ0FBQyxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFDLENBQUMifQ==

View File

@ -1,55 +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(){
this.timeout(10000);
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(600000);
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();

View File

@ -1,6 +1,6 @@
import * as plugins from "./smartnginx.plugins";
import * as plugins from './smartnginx.plugins';
// classes
export {NginxConfig} from "./smartnginx.classes.nginxconfig";
export {NginxProcess} from "./smartnginx.classes.nginxprocess";
export {NginxZone,zoneTypes} from "./smartnginx.classes.nginxzone";
export * from './smartnginx.classes.smartnginx';
export * from './smartnginx.classes.nginxprocess';
export * from './smartnginx.classes.nginxhost';

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

View File

@ -1,68 +0,0 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import * as snippets from "./smartnginx.snippets";
import { NginxZone } from "./smartnginx.classes.nginxzone";
import { NginxProcess } from "./smartnginx.classes.nginxprocess";
let allConfigs: NginxConfig[] = [];
export class NginxConfig {
zones: NginxZone[] = [];
cert: plugins.cert.Cert; // the Cert Instance from which the config gets its certificates
nginxProcess: NginxProcess = new NginxProcess(this);
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() {
let done = plugins.q.defer();
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(),
paths.nginxConfFile
);
// deploy zones
let promiseArray = [];
for (let zone of this.zones) {
let zoneDeployedPromise = zone.deploy(this.cert);
zoneDeployedPromise.then(() => {
plugins.beautylog.info(`Zone ${zone.zoneName} deployed!`);
this.nginxProcess.reloadConfig();
});
promiseArray.push(zoneDeployedPromise);
};
plugins.q.all(promiseArray)
.then(() => {
done.resolve();
});
return done.promise;
};
};

View File

@ -0,0 +1,62 @@
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);
}
}

View File

@ -1,70 +1,69 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
import { NginxZone } from "./smartnginx.classes.nginxzone";
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 {
started: boolean = false;
nginxConfig:NginxConfig;
nginxChildProcess: plugins.childProcess.ChildProcess;
constructor(nginxConfigArg) {
this.nginxConfig = nginxConfigArg;
};
public started: boolean = false;
public smartNginxRef: SmartNginx;
private nginxChildProcess: ChildProcess;
private smartshellInstance = new Smartshell({
executor: 'bash'
});
/**
* 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;
};
constructor(nginxRefArg: SmartNginx) {
this.smartNginxRef = nginxRefArg;
}
/**
* reload config
*/
reloadConfig(){
let done = plugins.q.defer();
if(this.started == false){
this.start()
} else {
this.nginxChildProcess.kill("SIGHUP");
};
plugins.beautylog.ok("NginxProcess has loaded the new config!")
done.resolve();
return done.promise;
};
/**
* 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!');
}
/**
* stop the nginx instance
*/
stop() {
let done = plugins.q.defer();
if (typeof this.nginxChildProcess != "undefined") {
this.nginxChildProcess.kill();
plugins.beautylog.info("stopped Nginx!");
} else {
plugins.beautylog.log("nginx already stopped!");
};
done.resolve();
return done.promise;
};
/**
* 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!');
}
/**
* checks if nginx is in path
*/
check(): boolean {
return;
};
/**
* stop the nginx instance
*/
public async stop() {
if (this.nginxChildProcess) {
this.smartshellInstance.exec('nginx -s quit');
this.started = false;
this.smartNginxRef.logger.log('info', 'stopped Nginx!');
} else {
this.smartNginxRef.logger.log('info', 'nginx already stopped!');
}
}
/**
* checks if nginx is in path
*/
public check(): boolean {
return;
}
}

View File

@ -1,34 +0,0 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
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;
};
};

View File

@ -0,0 +1,158 @@
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();
}
}
/**
* stops the smartnginx instance
*/
public async stop() {
if (this.nginxProcess) {
await this.nginxProcess.stop();
}
}
}

View File

@ -1,10 +1,9 @@
import * as plugins from "./smartnginx.plugins"
import * as plugins from './smartnginx.plugins';
// directories
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");
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 let nginxConfFile = plugins.path.join(nginxConfigBase,"nginx.conf");
export const nginxConfFile = plugins.path.join(nginxConfigDirPath, 'nginx.conf');

View File

@ -1,9 +1,20 @@
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 };

View File

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

@ -0,0 +1,17 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}