Compare commits
148 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 88d5bbb432 | |||
| 5781204c88 | |||
| 5700522b8a | |||
| e266a5b22e | |||
| c9eef34901 | |||
| da85018206 | |||
| cc54dfcf56 | |||
| 4016a957cf | |||
| 509ee83a15 | |||
| 1b6b2a24f1 | |||
| f18f008f84 | |||
| 9e1ed36def | |||
| 8a35725448 | |||
| 5438f83a40 | |||
| 5c4d5a4a85 | |||
| 1be3f7f388 | |||
| 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 | |||
| effe9210fc | |||
| e49a358b22 | |||
|
|
a2bf0315ac | ||
|
|
2caa3c3d1a | ||
|
|
92307b187d | ||
|
|
e0757600b6 | ||
|
|
244b21ca36 | ||
|
|
87eb7084c0 | ||
|
|
e77b3d0355 | ||
|
|
871ff06040 | ||
|
|
1f2105f75e | ||
|
|
43e8549042 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @gitzone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
||||
22
.gitignore
vendored
22
.gitignore
vendored
@@ -1,4 +1,20 @@
|
||||
node_modules/
|
||||
nginxconfig/zones/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
docs/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
@@ -1,36 +0,0 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Task Venture Capital 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.
|
||||
20
README.md
20
README.md
@@ -1,20 +0,0 @@
|
||||
# smartnginx
|
||||
control nginx from node, TypeScript ready
|
||||
|
||||
## Status
|
||||
[](https://gitlab.com/pushrocks/smartnginx/commits/master)
|
||||
|
||||
## 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
|
||||
});
|
||||
myNginxConfig.addZone(myNginxZone); // adds the zone to the config
|
||||
myNginxConfig.deploy(); // deploys the referenced NginxConfig and restarts nginx
|
||||
```
|
||||
59
changelog.md
Normal file
59
changelog.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-11-27 - 2.0.53 - fix(core)
|
||||
Refactor filesystem usage to smartfs async provider, update dependencies, tests and nginx config paths
|
||||
|
||||
- Replace @push.rocks/smartfile usage with @push.rocks/smartfs and introduce a shared SmartFs instance in plugins
|
||||
- Convert sync file operations to async fs APIs (plugins.fs.file(...).write / plugins.fs.directory(...).create) in SmartNginx and NginxHost
|
||||
- Adjust package.json: update test/build scripts, replace dependencies/devDependencies to new packages (@push.rocks/smartfs, @git.zone/*), and update versions
|
||||
- Update test imports to new tapbundle path and node:path; export default tap.start() and remove unused Qenv instantiation
|
||||
- Update internal path imports to 'node:path' and refactor smartnginx.plugins exports
|
||||
- Change generated nginx certificate/config paths in configs from /mnt/HC_Volume_11396573/... to /mnt/data/... and regenerate default cert files
|
||||
- Remove CI config (.gitlab-ci.yml) from repository
|
||||
|
||||
## 2024-05-29 - 2.0.52 - maintenance
|
||||
Various metadata and TypeScript configuration updates; release 2.0.52.
|
||||
|
||||
- Update package description.
|
||||
- Update tsconfig.
|
||||
- Update npmextra.json (githost) entries across multiple commits.
|
||||
- Release tag for 2.0.52.
|
||||
|
||||
## 2023-07-26 - 2.0.51 - maintenance
|
||||
Org migration and core fixes; release 2.0.51.
|
||||
|
||||
- Switch to new organization scheme.
|
||||
- fix(core): miscellaneous updates.
|
||||
- Release tag for 2.0.51.
|
||||
|
||||
## 2019-01-09..2019-08-20 - 2.0.19..2.0.50 - maintenance (multiple patch releases)
|
||||
Series of incremental patch releases with small fixes and cleanups.
|
||||
|
||||
- Many patch releases across the 2.0.x line (2.0.19 through 2.0.50).
|
||||
- Multiple "fix(core): update" commits addressing internal issues.
|
||||
- CI and cleanup fixes (including 2.0.38 cleanup).
|
||||
- Release tags for each patch.
|
||||
|
||||
## 2018-08-10 - 2.0.0 - breaking
|
||||
Major release and scope / packaging changes.
|
||||
|
||||
- 2.0.0 release with core updates.
|
||||
- BREAKING CHANGE: change scope to @pushrocks (package scope/name changed).
|
||||
- Various CI and core fixes accompanying the major release.
|
||||
|
||||
## 2016-08-03..2016-07-25 - 1.0.6..1.0.0 - release / maintenance
|
||||
1.x series consolidations, dependency updates and interface exports.
|
||||
|
||||
- Update dependencies and types.
|
||||
- Consolidate naming and start exporting interfaces.
|
||||
- Add license.
|
||||
- Release tags for 1.0.0 through 1.0.6.
|
||||
|
||||
## 2016-07-06..2016-07-25 - 0.0.0..0.1.0 - initial development
|
||||
Initial implementation and feature work establishing core functionality.
|
||||
|
||||
- Initial project setup, README and CI added.
|
||||
- Implement nginx communication and child process handling.
|
||||
- Start storing generated configs to filesystem and improve config handling.
|
||||
- Add snippets support and tests; multiple README improvements.
|
||||
- Early releases and version tags (0.0.0 through 0.1.0).
|
||||
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";
|
||||
var 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQ0EsSUFBWSxhQUFhLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUV0RCxVQUFVO0FBQ1YsK0NBQTBCLGtDQUFrQyxDQUFDO0FBQXJELG1FQUFxRDtBQUM3RCw2Q0FBa0MsZ0NBQWdDLENBQUM7QUFBM0QsNkRBQVM7QUFBQyw2REFBaUQ7QUFFbkUsVUFBVTtBQUNDLGVBQU8sR0FBRyxhQUFhLENBQUMifQ==
|
||||
10
dist/smartnginx.classes.nginxconfig.d.ts
vendored
10
dist/smartnginx.classes.nginxconfig.d.ts
vendored
@@ -1,10 +0,0 @@
|
||||
import { NginxZone } from "./smartnginx.classes.nginxzone";
|
||||
export declare class NginxConfig {
|
||||
zones: NginxZone[];
|
||||
isDeployed: boolean;
|
||||
constructor();
|
||||
addZone(zoneArg: NginxZone): void;
|
||||
listZones(): NginxZone[];
|
||||
removeZones(zoneArg: NginxZone): void;
|
||||
deploy(nginxRestartArg?: boolean): void;
|
||||
}
|
||||
47
dist/smartnginx.classes.nginxconfig.js
vendored
47
dist/smartnginx.classes.nginxconfig.js
vendored
@@ -1,47 +0,0 @@
|
||||
"use strict";
|
||||
var plugins = require("./smartnginx.plugins");
|
||||
var paths = require("./smartnginx.paths");
|
||||
var command = require("./smartnginx.command");
|
||||
var snippets = require("./smartnginx.snippets");
|
||||
var allConfigs = [];
|
||||
var NginxConfig = (function () {
|
||||
function NginxConfig() {
|
||||
this.isDeployed = false;
|
||||
}
|
||||
;
|
||||
// interact with Zones
|
||||
NginxConfig.prototype.addZone = function (zoneArg) {
|
||||
};
|
||||
NginxConfig.prototype.listZones = function () {
|
||||
return this.zones;
|
||||
};
|
||||
;
|
||||
NginxConfig.prototype.removeZones = function (zoneArg) {
|
||||
};
|
||||
// handle deployment of zones
|
||||
NginxConfig.prototype.deploy = function (nginxRestartArg) {
|
||||
if (nginxRestartArg === void 0) { nginxRestartArg = false; }
|
||||
plugins.smartfile.fs.remove(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDir(paths.nginxConfigBase);
|
||||
for (var _i = 0, allConfigs_1 = allConfigs; _i < allConfigs_1.length; _i++) {
|
||||
var config = allConfigs_1[_i];
|
||||
config.isDeployed = false;
|
||||
}
|
||||
;
|
||||
this.isDeployed = true;
|
||||
for (var _a = 0, _b = this.zones; _a < _b.length; _a++) {
|
||||
var zone = _b[_a];
|
||||
zone.deploy();
|
||||
}
|
||||
;
|
||||
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), plugins.path.join(paths.nginxConfigBase, "nginx.conf"));
|
||||
if (nginxRestartArg) {
|
||||
command.restart(this);
|
||||
}
|
||||
};
|
||||
;
|
||||
return NginxConfig;
|
||||
}());
|
||||
exports.NginxConfig = NginxConfig;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELElBQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsSUFBWSxPQUFPLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUNoRCxJQUFZLFFBQVEsV0FBTSx1QkFDMUIsQ0FBQyxDQURnRDtBQUVqRCxJQUFJLFVBQVUsR0FBaUIsRUFBRSxDQUFDO0FBRWxDO0lBR0k7UUFEQSxlQUFVLEdBQVcsS0FBSyxDQUFDO0lBRzNCLENBQUM7O0lBRUQsc0JBQXNCO0lBQ3RCLDZCQUFPLEdBQVAsVUFBUSxPQUFpQjtJQUV6QixDQUFDO0lBQ0QsK0JBQVMsR0FBVDtRQUNJLE1BQU0sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDO0lBQ3RCLENBQUM7O0lBQ0QsaUNBQVcsR0FBWCxVQUFZLE9BQWlCO0lBRTdCLENBQUM7SUFFRCw2QkFBNkI7SUFDN0IsNEJBQU0sR0FBTixVQUFPLGVBQStCO1FBQS9CLCtCQUErQixHQUEvQix1QkFBK0I7UUFDbEMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxlQUFlLENBQUMsQ0FBQztRQUNuRCxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxTQUFTLENBQUMsS0FBSyxDQUFDLGVBQWUsQ0FBQyxDQUFDO1FBQ3RELEdBQUcsQ0FBQSxDQUFlLFVBQVUsRUFBVix5QkFBVSxFQUFWLHdCQUFVLEVBQVYsSUFBVSxDQUFDO1lBQXpCLElBQUksTUFBTSxtQkFBQTtZQUNWLE1BQU0sQ0FBQyxVQUFVLEdBQUcsS0FBSyxDQUFDO1NBQzdCO1FBQUEsQ0FBQztRQUNGLElBQUksQ0FBQyxVQUFVLEdBQUcsSUFBSSxDQUFDO1FBQ3ZCLEdBQUcsQ0FBQSxDQUFhLFVBQVUsRUFBVixLQUFBLElBQUksQ0FBQyxLQUFLLEVBQVYsY0FBVSxFQUFWLElBQVUsQ0FBQztZQUF2QixJQUFJLElBQUksU0FBQTtZQUNSLElBQUksQ0FBQyxNQUFNLEVBQUUsQ0FBQztTQUNqQjtRQUFBLENBQUM7UUFDRixPQUFPLENBQUMsU0FBUyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQzdCLFFBQVEsQ0FBQyxtQkFBbUIsRUFBRSxFQUM5QixPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsZUFBZSxFQUFDLFlBQVksQ0FBQyxDQUN4RCxDQUFDO1FBQ0YsRUFBRSxDQUFBLENBQUMsZUFBZSxDQUFDLENBQUEsQ0FBQztZQUNoQixPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO1FBQzFCLENBQUM7SUFDTCxDQUFDOztJQUVMLGtCQUFDO0FBQUQsQ0FBQyxBQXRDRCxJQXNDQztBQXRDWSxtQkFBVyxjQXNDdkIsQ0FBQTtBQUFBLENBQUMifQ==
|
||||
14
dist/smartnginx.classes.nginxzone.d.ts
vendored
14
dist/smartnginx.classes.nginxzone.d.ts
vendored
@@ -1,14 +0,0 @@
|
||||
export declare enum zoneTypes {
|
||||
reverseProxy = 0,
|
||||
static = 1,
|
||||
}
|
||||
export declare class NginxZone {
|
||||
zoneName: string;
|
||||
configString: string;
|
||||
constructor(optionsArg: {
|
||||
zoneName: string;
|
||||
type: zoneTypes;
|
||||
destination: string;
|
||||
});
|
||||
deploy(): void;
|
||||
}
|
||||
24
dist/smartnginx.classes.nginxzone.js
vendored
24
dist/smartnginx.classes.nginxzone.js
vendored
@@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
var plugins = require("./smartnginx.plugins");
|
||||
var paths = require("./smartnginx.paths");
|
||||
var snippets = require("./smartnginx.snippets");
|
||||
(function (zoneTypes) {
|
||||
zoneTypes[zoneTypes["reverseProxy"] = 0] = "reverseProxy";
|
||||
zoneTypes[zoneTypes["static"] = 1] = "static";
|
||||
})(exports.zoneTypes || (exports.zoneTypes = {}));
|
||||
var zoneTypes = exports.zoneTypes;
|
||||
var NginxZone = (function () {
|
||||
function NginxZone(optionsArg) {
|
||||
this.configString = snippets.getZoneConfigString(optionsArg.zoneName, optionsArg.destination);
|
||||
}
|
||||
;
|
||||
NginxZone.prototype.deploy = function () {
|
||||
var filePath = plugins.path.join(paths.nginxZoneBase, this.zoneName + ".conf");
|
||||
plugins.smartfile.memory.toFsSync(this.configString, filePath);
|
||||
};
|
||||
;
|
||||
return NginxZone;
|
||||
}());
|
||||
exports.NginxZone = NginxZone;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54em9uZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguY2xhc3Nlcy5uZ2lueHpvbmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDaEQsSUFBWSxLQUFLLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUU1QyxJQUFZLFFBQVEsV0FBTSx1QkFDMUIsQ0FBQyxDQURnRDtBQUNqRCxXQUFZLFNBQVM7SUFDZCx5REFBWSxDQUFBO0lBQ1osNkNBQU0sQ0FBQTtBQUNiLENBQUMsRUFIVyxpQkFBUyxLQUFULGlCQUFTLFFBR3BCO0FBSEQsSUFBWSxTQUFTLEdBQVQsaUJBR1gsQ0FBQTtBQUVEO0lBR0ksbUJBQVksVUFJWDtRQUNHLElBQUksQ0FBQyxZQUFZLEdBQUcsUUFBUSxDQUFDLG1CQUFtQixDQUFDLFVBQVUsQ0FBQyxRQUFRLEVBQUMsVUFBVSxDQUFDLFdBQVcsQ0FBQyxDQUFDO0lBQ2pHLENBQUM7O0lBQ0QsMEJBQU0sR0FBTjtRQUNJLElBQUksUUFBUSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxhQUFhLEVBQUMsSUFBSSxDQUFDLFFBQVEsR0FBRyxPQUFPLENBQUMsQ0FBQztRQUM5RSxPQUFPLENBQUMsU0FBUyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsSUFBSSxDQUFDLFlBQVksRUFBQyxRQUFRLENBQUMsQ0FBQztJQUNsRSxDQUFDOztJQUNMLGdCQUFDO0FBQUQsQ0FBQyxBQWRELElBY0M7QUFkWSxpQkFBUyxZQWNyQixDQUFBO0FBQUEsQ0FBQyJ9
|
||||
14
dist/smartnginx.command.d.ts
vendored
14
dist/smartnginx.command.d.ts
vendored
@@ -1,14 +0,0 @@
|
||||
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
|
||||
/**
|
||||
* starts nginx
|
||||
*/
|
||||
export declare let start: (configArg: NginxConfig) => void;
|
||||
export declare let restart: (configArg: NginxConfig) => void;
|
||||
/**
|
||||
* stops nginx
|
||||
*/
|
||||
export declare let stop: () => void;
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
export declare let check: () => boolean;
|
||||
22
dist/smartnginx.command.js
vendored
22
dist/smartnginx.command.js
vendored
@@ -1,22 +0,0 @@
|
||||
"use strict";
|
||||
/**
|
||||
* starts nginx
|
||||
*/
|
||||
exports.start = function (configArg) {
|
||||
};
|
||||
exports.restart = function (configArg) {
|
||||
exports.stop();
|
||||
exports.start(configArg);
|
||||
};
|
||||
/**
|
||||
* stops nginx
|
||||
*/
|
||||
exports.stop = function () {
|
||||
};
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
exports.check = function () {
|
||||
return;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jb21tYW5kLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jb21tYW5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFJQTs7R0FFRztBQUNRLGFBQUssR0FBRyxVQUFDLFNBQXFCO0FBRXpDLENBQUMsQ0FBQztBQUVTLGVBQU8sR0FBRyxVQUFDLFNBQXFCO0lBQ3ZDLFlBQUksRUFBRSxDQUFDO0lBQ1AsYUFBSyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQ3JCLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ1EsWUFBSSxHQUFHO0FBRWxCLENBQUMsQ0FBQztBQUVGOztHQUVHO0FBQ1EsYUFBSyxHQUFHO0lBQ2YsTUFBTSxDQUFDO0FBQ1gsQ0FBQyxDQUFDIn0=
|
||||
3
dist/smartnginx.paths.d.ts
vendored
3
dist/smartnginx.paths.d.ts
vendored
@@ -1,3 +0,0 @@
|
||||
export declare let packageBase: string;
|
||||
export declare let nginxConfigBase: string;
|
||||
export declare let nginxZoneBase: string;
|
||||
6
dist/smartnginx.paths.js
vendored
6
dist/smartnginx.paths.js
vendored
@@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
var 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");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQVksT0FBTyxXQUFNLHNCQUV6QixDQUFDLENBRjhDO0FBRXBDLG1CQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFDO0FBQ2pELHVCQUFlLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsbUJBQVcsRUFBQyxjQUFjLENBQUMsQ0FBQztBQUNoRSxxQkFBYSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHVCQUFlLEVBQUMsT0FBTyxDQUFDLENBQUMifQ==
|
||||
7
dist/smartnginx.plugins.d.ts
vendored
7
dist/smartnginx.plugins.d.ts
vendored
@@ -1,7 +0,0 @@
|
||||
import "typings-global";
|
||||
export import cert = require("cert");
|
||||
export import path = require("path");
|
||||
export import q = require("q");
|
||||
export declare let shelljs: any;
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartstring = require("smartstring");
|
||||
9
dist/smartnginx.plugins.js
vendored
9
dist/smartnginx.plugins.js
vendored
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.cert = require("cert");
|
||||
exports.path = require("path");
|
||||
exports.q = require("q");
|
||||
exports.shelljs = require("shelljs");
|
||||
exports.smartfile = require("smartfile");
|
||||
exports.smartstring = require("smartstring");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsWUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUNwQixlQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQzFCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9
|
||||
2
dist/smartnginx.snippets.d.ts
vendored
2
dist/smartnginx.snippets.d.ts
vendored
@@ -1,2 +0,0 @@
|
||||
export declare let getBaseConfigString: () => void;
|
||||
export declare let getZoneConfigString: (zoneNameArg: string, destinationIpArg: string) => string;
|
||||
10
dist/smartnginx.snippets.js
vendored
10
dist/smartnginx.snippets.js
vendored
@@ -1,10 +0,0 @@
|
||||
"use strict";
|
||||
var plugins = require("./smartnginx.plugins");
|
||||
exports.getBaseConfigString = function () {
|
||||
var baseConfig = plugins.smartstring.indent.normalize("\n\t\tuser www-data;\n\t\tworker_processes auto;\n\t\tpid /run/nginx.pid;\n\n\t\tevents {\n\t\t\tworker_connections 768;\n\t\t\t# multi_accept on;\n\t\t}\n\n\t\thttp {\n\t\t\tserver_names_hash_bucket_size 128;\n\n\t\t\t##\n\t\t\t# Basic Settings\n\t\t\t##\n\n\t\t\tsendfile on;\n\t\t\ttcp_nopush on;\n\t\t\ttcp_nodelay on;\n\t\t\tkeepalive_timeout 65;\n\t\t\ttypes_hash_max_size 2048;\n\t\t\t# server_tokens off;\n\n\t\t\t# server_names_hash_bucket_size 64;\n\t\t\t# server_name_in_redirect off;\n\n\t\t\tinclude /etc/nginx/mime.types;\n\t\t\tdefault_type application/octet-stream;\n\n\t\t\t##\n\t\t\t# SSL Settings\n\t\t\t##\n\n\t\t\tssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE\n\t\t\tssl_prefer_server_ciphers on;\n\n\t\t\t##\n\t\t\t# Logging Settings\n\t\t\t##\n\n\t\t\taccess_log /var/log/nginx/access.log;\n\t\t\terror_log /var/log/nginx/error.log;\n\n\t\t\t##\n\t\t\t# Gzip Settings\n\t\t\t##\n\n\t\t\tgzip on;\n\t\t\tgzip_disable \"msie6\";\n\n\t\t\t# gzip_vary on;\n\t\t\t# gzip_proxied any;\n\t\t\t# gzip_comp_level 6;\n\t\t\t# gzip_buffers 16 8k;\n\t\t\t# gzip_http_version 1.1;\n\t\t\t# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;\n\n\t\t\t##\n\t\t\t# Virtual Host Configs\n\t\t\t##\n\n\t\t\tinclude /etc/nginx/conf.d/*.conf;\n\t\t\tinclude /etc/nginx/sites-enabled/*;\n\t\t}\n\t\tdaemon off;\n\t");
|
||||
};
|
||||
exports.getZoneConfigString = function (zoneNameArg, destinationIpArg) {
|
||||
var zoneConfig = plugins.smartstring.indent.normalize("\n\t\tupstream " + zoneNameArg + " {\n\t\t\tserver " + destinationIpArg + ";\n\t\t}\n\n\t\tserver {\n\t\t\tlisten *:80 ;\n\t\t\tserver_name " + zoneNameArg + ";\n\t\t\trewrite ^ https://" + zoneNameArg + "$request_uri? permanent;\n\t\t}\n\n\t\tserver {\n\t\t\tlisten *:443 ssl;\n\t\t\tserver_name " + zoneNameArg + ";\n\t\t\tssl_certificate /LE_CERTS/" + zoneNameArg + "/fullchain.pem;\n\t\t\tssl_certificate_key /LE_CERTS/" + zoneNameArg + "/privkey.pem;\n\n\t\t\tlocation / {\n\t\t\t\tproxy_pass http://" + zoneNameArg + ";\n\t\t\t\tinclude /etc/nginx/proxy_params;\n\t\t\t}\n\t\t\tlocation ~ /.git {\n\t\t\t\tdeny all;\n\t\t\t}\n\t\t}\n\t");
|
||||
return zoneConfig;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5zbmlwcGV0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguc25pcHBldHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDckMsMkJBQW1CLEdBQUc7SUFDaEMsSUFBSSxVQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDLDY0Q0FrRXJELENBQUMsQ0FBQztBQUNKLENBQUMsQ0FBQTtBQUdVLDJCQUFtQixHQUFHLFVBQUMsV0FBa0IsRUFBQyxnQkFBdUI7SUFDM0UsSUFBSSxVQUFVLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDLG9CQUMxQyxXQUFXLHlCQUNaLGdCQUFnQix5RUFLWCxXQUFXLDBDQUNFLFdBQVcsb0dBS3hCLFdBQVcsMkNBQ0csV0FBVyw2REFDUCxXQUFXLHVFQUd0QixXQUFXLDBIQU9qQyxDQUFDLENBQUM7SUFDSCxNQUFNLENBQUMsVUFBVSxDQUFDO0FBQ25CLENBQUMsQ0FBQyJ9
|
||||
15
nginxconfig/default.private.pem
Normal file
15
nginxconfig/default.private.pem
Normal file
@@ -0,0 +1,15 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICWwIBAAKBgQCHoQbEbAo/0ZDFU9AkubBRi8FeKdhCFrzK+wXZD9JnEJRa3q6o
|
||||
CI+6H3YLYleGGP8Vkwca8ykz5BX0MrKAlZWpoEpqgm2lVCBKh9mqCG1bN0aPdlwh
|
||||
E24/HZFbeVgyJBvH/7XZJDGlm638dSMoXMmPtwLfq1uTAmHwtHBEqdiLFwIDAQAB
|
||||
AoGAJWXibtD3toc7qx2kPCwzkRi/Ng7FwdtxLWswPp0dQCwTLEdQ06agswqvyw3P
|
||||
4nsMA0/qWqUIDHXtE8vS6p/Uh21aKTYNgHJA4VZdJvh5Zhogq77dtGFyME7T3914
|
||||
isamRo8hxemijJG9oml7y+jW/xnMFhe98dqKf9k0RNI9G1kCQQDHhInM8HEJWnRX
|
||||
ckkhGoel7HlfpTaLYIO7Ls4ErsNmBQjralRZVX1+g4+h4/QLCcOYqihNDgSUZMEt
|
||||
aEC82c4LAkEArgZXP/gaua0tylBwQETOyUip2apVOvArmH9xLL9qTkXueV39skZb
|
||||
36cO9RK7C+HTY4hGNcXDdihxs+Fa4sD6pQJAQc6FZQMpRVyAYxde53xIoYGNxu5H
|
||||
P1FmIacebIz4Bf5DIuK/T3fTHJdoGI2HQNzHluMIx+GHwSo6TS/FqoRsYQJAe/ia
|
||||
aUC20TU0nJ6nCLG72hqAnUZBh0YW2IFZP3ZxJaed1ioGE90Zj/8zoZShWTqb25j1
|
||||
41KqBt+S+ID+vPCa3QJABo8fEGIy/g7M5OB5euLHQLvCvYJDn9YWAryhRedR1B2e
|
||||
zEZOO0qxUJSjMdnYFYG6Na/poM3atnJ4W8pJzOtA4w==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
6
nginxconfig/default.public.pem
Normal file
6
nginxconfig/default.public.pem
Normal file
@@ -0,0 +1,6 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCHoQbEbAo/0ZDFU9AkubBRi8Fe
|
||||
KdhCFrzK+wXZD9JnEJRa3q6oCI+6H3YLYleGGP8Vkwca8ykz5BX0MrKAlZWpoEpq
|
||||
gm2lVCBKh9mqCG1bN0aPdlwhE24/HZFbeVgyJBvH/7XZJDGlm638dSMoXMmPtwLf
|
||||
q1uTAmHwtHBEqdiLFwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
27
nginxconfig/hosts/default.private.pem
Normal file
27
nginxconfig/hosts/default.private.pem
Normal file
@@ -0,0 +1,27 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEAuO16Nu4tMkmBqsNWezt3ENqnsbWNUqC+curHyXURaoIH2wQ1
|
||||
6DIZaBIbO/WndNisMy6TnxJtiMVbKGKjkRH4w3qegthIRCKLD3+Yl1ffqpHRz19h
|
||||
kNxVg4HfXRQMfH0Pnvd/4wB7g2mapk8SMwsTuEZ0j/7dAwc0dqw94g+aehgZlvxU
|
||||
DFQjI/4kU9EiheDZ9TPREBMfeIb82zapINekKq5TkN/euWfsfpbZZ6qWZvTX8Neg
|
||||
ulKOtDCCFauXKv2LNqy4jxWQef2XfMT8Jr4Txud3F8zqfexJYq5ywjH07ecsyi7a
|
||||
/ifv7VLNXUEgwI6OFJHYnFZ314S6KlurocQUWQIDAQABAoIBAAIMpnWrBrSa+d5X
|
||||
whB9uX27XITnXKpoAguNfHivvONBrcXGWVl+zkKh3ip4RFIfE7IjXpyQ6vEalD5j
|
||||
zDh4uiWflt3cVFldDUISdmUb1pEYM5YcMN1c/RRujikQ8qK3ExhyLtqh7Eu8GBnR
|
||||
L7rQ6x9ZoBAAtJT4Wr6rIeEmfW16lunOu97mTi/RL//EHQvlBPgyr2sHLee2aPWV
|
||||
jmC4607vV+xNJPC4qd+6HJDjaXi6hNooVDO8jX48RJUVozMRX7i8GIoDotvObVbA
|
||||
SCqlhbWyawzbCX1p5nvtdOZ0muSIDILudifFUzRzBm0sSL0MxIT0s6OYaQuU0moH
|
||||
Q1nOr+UCgYEA94R/MkApusWYjRcNEPPE2cB1QvtoEDdfhPzwzg1xympRzn8gOwin
|
||||
tpJ25H+dYHeIR5TB5GiqKRY/zwqqqiplEQRkIL+aT/mYqM/vSfchm+gVbBYZL7ql
|
||||
FrE9h+i+mf0/GNoRV3VirWjIjTqBW3DQ0KvxBOos9gJCJA6pMD0xQo0CgYEAv0Pf
|
||||
BvZpskgmxdOGlynUbfu9hQWOqbagU6U1dUwzYbO2EYqjxZeJn5974vJ5XlHAHy3R
|
||||
WuVfGjdiNIph+mDiBFK7wUih6dwVUrKf8H1fucsprfmRkaiKnofaefrlWHMnqo45
|
||||
vWAXkQoJpnR7afQmk3lK8geejMIo/M5Wm+VuS/0CgYA25iRwONsImhsj8CDtyaO3
|
||||
yIA5wxlpv15oWNHwYfsDMmHCs1+quFi6nfHQ7J0zcE/B0LTQvIZBZrXwbiU8aPrR
|
||||
s2+h891+L5Y0myov9ah2tBtMRfqAI53KUrWbF3xvG0SLdpKyG08vtzYEXR2j8nne
|
||||
TsS+mlIunoGdDcNo96mdYQKBgDz7B72xjMuBw5LpOQ0zEf6q96bUucKUbpOcpemr
|
||||
DOrGoHMBT+vsv7073QTjqByRVf7a3dfsL6EtLUtxH4Hzp7wXILOkU7M7LzU5rFLB
|
||||
tmaHRteoLWhSYzfeOqMPglXsCSaQyAn//COLHr6KftquNCpqzqFSGpPoR6cqpmR4
|
||||
Bu2FAoGBAN+UVwhXtSYG89pYFw5u4Oa2XwaVciaqGSkXR0Oyb8pBx65AX6Byy1FD
|
||||
6IooFiAkHqDDz2iIPx7mxzTrHBfKcaHsUcgT5aXr720A6/aD6W5PsVdebWoMMTyA
|
||||
OqFdoeXdMWUzCOWQYp6ViD8f0MQydHppOhugEivReRP700C1WVnx
|
||||
-----END RSA PRIVATE KEY-----
|
||||
19
nginxconfig/hosts/default.public.pem
Normal file
19
nginxconfig/hosts/default.public.pem
Normal file
@@ -0,0 +1,19 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDBDCCAeygAwIBAgIJZid+XT7/NTaWMA0GCSqGSIb3DQEBBQUAMB4xHDAaBgNV
|
||||
BAMTE3NlbGZzaWduZWQuZ2l0LnpvbmUwHhcNMjUxMTI3MTMxMzM0WhcNMjYxMTI3
|
||||
MTMxMzM0WjAeMRwwGgYDVQQDExNzZWxmc2lnbmVkLmdpdC56b25lMIIBIjANBgkq
|
||||
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuO16Nu4tMkmBqsNWezt3ENqnsbWNUqC+
|
||||
curHyXURaoIH2wQ16DIZaBIbO/WndNisMy6TnxJtiMVbKGKjkRH4w3qegthIRCKL
|
||||
D3+Yl1ffqpHRz19hkNxVg4HfXRQMfH0Pnvd/4wB7g2mapk8SMwsTuEZ0j/7dAwc0
|
||||
dqw94g+aehgZlvxUDFQjI/4kU9EiheDZ9TPREBMfeIb82zapINekKq5TkN/euWfs
|
||||
fpbZZ6qWZvTX8NegulKOtDCCFauXKv2LNqy4jxWQef2XfMT8Jr4Txud3F8zqfexJ
|
||||
Yq5ywjH07ecsyi7a/ifv7VLNXUEgwI6OFJHYnFZ314S6KlurocQUWQIDAQABo0Uw
|
||||
QzAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIC9DAmBgNVHREEHzAdhhtodHRwOi8v
|
||||
ZXhhbXBsZS5vcmcvd2ViaWQjbWUwDQYJKoZIhvcNAQEFBQADggEBAH3qUHaBnNn+
|
||||
e1qlZ0gUooJlLXU5tLGR9cVFV1dKuE5yxZhT0qal4A6Vif1mGKYXmHC4q0/atNsQ
|
||||
RBvrbpoVtJxWpb6iIh1L5WWeP5OxqeLwZ8gp2Qj67CkwmccjIS66kkpwHBkBmXU9
|
||||
nRlmGOj9OBHczqE0cp4dW6pCVvRtzC+wTX9oqAdmjyD8S8oo8I2fjCL4pJTPQtbV
|
||||
RlaryWxlxscXYArA7iE9A5Cl5DdJtkOKS48Rbfw3BEQpgL0J4VeF8Lbb+ryk6BbG
|
||||
XXkkH570cIdTs588gdfhkS8T6NIl+1Aicqmf+v6j3MHrzyLK3SZTQ83hoCRAEMfW
|
||||
SPkrHSeL6h8=
|
||||
-----END CERTIFICATE-----
|
||||
31
nginxconfig/hosts/test100.bleu.de.conf
Normal file
31
nginxconfig/hosts/test100.bleu.de.conf
Normal 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 /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/test100.bleu.de.public.pem;
|
||||
ssl_certificate_key /mnt/data/lossless/push.rocks/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;
|
||||
}
|
||||
}
|
||||
1
nginxconfig/hosts/test100.bleu.de.private.pem
Normal file
1
nginxconfig/hosts/test100.bleu.de.private.pem
Normal file
@@ -0,0 +1 @@
|
||||
some private
|
||||
1
nginxconfig/hosts/test100.bleu.de.public.pem
Normal file
1
nginxconfig/hosts/test100.bleu.de.public.pem
Normal file
@@ -0,0 +1 @@
|
||||
some public
|
||||
31
nginxconfig/hosts/test102.bleu.de.conf
Normal file
31
nginxconfig/hosts/test102.bleu.de.conf
Normal 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 /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/test102.bleu.de.public.pem;
|
||||
ssl_certificate_key /mnt/data/lossless/push.rocks/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;
|
||||
}
|
||||
}
|
||||
1
nginxconfig/hosts/test102.bleu.de.private.pem
Normal file
1
nginxconfig/hosts/test102.bleu.de.private.pem
Normal file
@@ -0,0 +1 @@
|
||||
some private
|
||||
1
nginxconfig/hosts/test102.bleu.de.public.pem
Normal file
1
nginxconfig/hosts/test102.bleu.de.public.pem
Normal file
@@ -0,0 +1 @@
|
||||
some public
|
||||
@@ -1,6 +1,6 @@
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
pid /run/nginx/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
@@ -8,7 +8,7 @@ events {
|
||||
}
|
||||
|
||||
http {
|
||||
server_names_hash_bucket_size 128;
|
||||
server_names_hash_bucket_size 128;
|
||||
|
||||
##
|
||||
# Basic Settings
|
||||
@@ -59,7 +59,21 @@ http {
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
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 /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/default.public.pem;
|
||||
ssl_certificate_key /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/default.private.pem;
|
||||
rewrite ^ https://git.zone redirect;
|
||||
}
|
||||
|
||||
include /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
daemon off;
|
||||
daemon off;
|
||||
|
||||
29
npmextra.json
Normal file
29
npmextra.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"npmdocker": {},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartnginx",
|
||||
"description": "A TypeScript library for controlling Nginx from Node.js, with support for generating and managing Nginx configurations dynamically.",
|
||||
"npmPackagename": "@push.rocks/smartnginx",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"nginx",
|
||||
"node.js",
|
||||
"TypeScript",
|
||||
"configuration management",
|
||||
"web server",
|
||||
"reverse proxy",
|
||||
"SSL certificates"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
||||
67
package.json
67
package.json
@@ -1,36 +1,65 @@
|
||||
{
|
||||
"name": "smartnginx",
|
||||
"version": "0.0.3",
|
||||
"description": "control nginx from node, TypeScript ready",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"name": "@push.rocks/smartnginx",
|
||||
"version": "2.0.53",
|
||||
"private": false,
|
||||
"description": "A TypeScript library for controlling Nginx from Node.js, with support for generating and managing Nginx configurations dynamically.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "tstest test/ --verbose",
|
||||
"cleanTest": "(rm -r nginxconfig) && npm run test",
|
||||
"build": "(tsbuild tsfolders --allowimplicitany)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartnginx.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartnginx.git"
|
||||
},
|
||||
"keywords": [
|
||||
"nginx"
|
||||
"nginx",
|
||||
"node.js",
|
||||
"TypeScript",
|
||||
"configuration management",
|
||||
"web server",
|
||||
"reverse proxy",
|
||||
"SSL certificates"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartnginx/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartnginx",
|
||||
"dependencies": {
|
||||
"@types/q": "0.0.25-alpha",
|
||||
"cert": "0.0.13",
|
||||
"q": "^1.4.1",
|
||||
"shelljs": "^0.7.0",
|
||||
"smartfile": "^4.0.10",
|
||||
"smartstring": "^2.0.14"
|
||||
"@push.rocks/lik": "^6.2.2",
|
||||
"@push.rocks/smartfs": "^1.1.0",
|
||||
"@push.rocks/smartlog": "^3.1.10",
|
||||
"@push.rocks/smartpath": "^6.0.0",
|
||||
"@push.rocks/smartpromise": "^4.2.3",
|
||||
"@push.rocks/smartshell": "^3.3.0",
|
||||
"@push.rocks/smartstring": "^4.1.0",
|
||||
"@push.rocks/smartunique": "^3.0.9",
|
||||
"selfsigned": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts-g": "^5.2.6",
|
||||
"should": "^9.0.2",
|
||||
"typings-test": "^1.0.1"
|
||||
}
|
||||
"@git.zone/tsbuild": "^3.1.0",
|
||||
"@git.zone/tsrun": "^2.0.0",
|
||||
"@git.zone/tstest": "^3.1.3",
|
||||
"@push.rocks/qenv": "^6.1.3"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"type": "module",
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
||||
8315
pnpm-lock.yaml
generated
Normal file
8315
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
267
readme.md
Normal file
267
readme.md
Normal file
@@ -0,0 +1,267 @@
|
||||
# @push.rocks/smartnginx
|
||||
|
||||
Control Nginx programmatically from Node.js with full TypeScript support 🚀
|
||||
|
||||
## Issue Reporting and Security
|
||||
|
||||
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
||||
|
||||
## Features
|
||||
|
||||
- 🎯 **Dynamic Configuration** - Generate and manage Nginx configs on the fly
|
||||
- 🔒 **SSL/TLS Ready** - Built-in support for SSL certificates with automatic HTTP→HTTPS redirects
|
||||
- 🔄 **Hot Reload** - Apply configuration changes without downtime
|
||||
- 📦 **Zero-Config Defaults** - Self-signed certificates auto-generated for immediate testing
|
||||
- 🎛️ **Reverse Proxy Made Easy** - Set up proxy hosts with a single method call
|
||||
- 🧠 **Smart Diffing** - Only reloads Nginx when configurations actually change
|
||||
- 📝 **TypeScript First** - Full type definitions included
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
pnpm add @push.rocks/smartnginx
|
||||
# or
|
||||
npm install @push.rocks/smartnginx
|
||||
```
|
||||
|
||||
> **Prerequisites**: Nginx must be installed and available in your system PATH.
|
||||
|
||||
## Quick Start
|
||||
|
||||
```typescript
|
||||
import { SmartNginx } from '@push.rocks/smartnginx';
|
||||
|
||||
// Create a SmartNginx instance with a default fallback URL
|
||||
const nginx = new SmartNginx({
|
||||
defaultProxyUrl: 'https://your-default-site.com'
|
||||
});
|
||||
|
||||
// Add a reverse proxy host
|
||||
nginx.addHostCandidate({
|
||||
hostName: 'api.example.com',
|
||||
destination: 'localhost',
|
||||
destinationPort: 3000,
|
||||
privateKey: '<your-ssl-private-key>',
|
||||
publicKey: '<your-ssl-certificate>'
|
||||
});
|
||||
|
||||
// Deploy and start Nginx
|
||||
await nginx.deploy();
|
||||
```
|
||||
|
||||
That's it! Your reverse proxy is now running 🎉
|
||||
|
||||
## Usage
|
||||
|
||||
### Creating the SmartNginx Instance
|
||||
|
||||
The `SmartNginx` class is your main interface for managing Nginx:
|
||||
|
||||
```typescript
|
||||
import { SmartNginx } from '@push.rocks/smartnginx';
|
||||
|
||||
const nginx = new SmartNginx({
|
||||
defaultProxyUrl: 'https://fallback.example.com', // Where unmatched requests go
|
||||
logger: myCustomLogger // Optional: pass a @push.rocks/smartlog instance
|
||||
});
|
||||
```
|
||||
|
||||
### Adding Host Configurations
|
||||
|
||||
Each host represents a domain/subdomain with its proxy rules and SSL certificates:
|
||||
|
||||
```typescript
|
||||
// Add a host using addHostCandidate()
|
||||
const myHost = nginx.addHostCandidate({
|
||||
hostName: 'app.example.com', // Domain name
|
||||
destination: '127.0.0.1', // Backend server address
|
||||
destinationPort: 8080, // Backend port
|
||||
privateKey: sslPrivateKeyPem, // SSL private key (PEM format)
|
||||
publicKey: sslCertificatePem // SSL certificate (PEM format)
|
||||
});
|
||||
```
|
||||
|
||||
### Multi-Host Setup
|
||||
|
||||
Run multiple sites through a single Nginx instance:
|
||||
|
||||
```typescript
|
||||
// Production API
|
||||
nginx.addHostCandidate({
|
||||
hostName: 'api.myapp.com',
|
||||
destination: 'localhost',
|
||||
destinationPort: 3000,
|
||||
privateKey: apiPrivateKey,
|
||||
publicKey: apiCertificate
|
||||
});
|
||||
|
||||
// Admin panel
|
||||
nginx.addHostCandidate({
|
||||
hostName: 'admin.myapp.com',
|
||||
destination: 'localhost',
|
||||
destinationPort: 4000,
|
||||
privateKey: adminPrivateKey,
|
||||
publicKey: adminCertificate
|
||||
});
|
||||
|
||||
// Staging environment
|
||||
nginx.addHostCandidate({
|
||||
hostName: 'staging.myapp.com',
|
||||
destination: '192.168.1.100',
|
||||
destinationPort: 8080,
|
||||
privateKey: stagingPrivateKey,
|
||||
publicKey: stagingCertificate
|
||||
});
|
||||
|
||||
// Deploy all at once
|
||||
await nginx.deploy();
|
||||
```
|
||||
|
||||
### Deploying Configurations
|
||||
|
||||
The `deploy()` method is smart about changes:
|
||||
|
||||
```typescript
|
||||
// First deploy - writes configs and starts Nginx
|
||||
await nginx.deploy();
|
||||
|
||||
// Add more hosts dynamically
|
||||
nginx.addHostCandidate({
|
||||
hostName: 'newsite.example.com',
|
||||
destination: 'localhost',
|
||||
destinationPort: 5000,
|
||||
privateKey: newPrivateKey,
|
||||
publicKey: newCertificate
|
||||
});
|
||||
|
||||
// Second deploy - detects changes, updates configs, hot-reloads Nginx
|
||||
await nginx.deploy();
|
||||
|
||||
// If you call deploy() with no changes, it skips the reload (efficient!)
|
||||
await nginx.deploy(); // → "hosts have not diverged, skipping nginx reload"
|
||||
```
|
||||
|
||||
### Querying Deployed Hosts
|
||||
|
||||
```typescript
|
||||
// Get all deployed hosts
|
||||
const hosts = await nginx.listDeployedHosts();
|
||||
console.log(`Running ${hosts.length} hosts`);
|
||||
|
||||
// Find a specific host by domain
|
||||
const apiHost = nginx.getDeployedNginxHostByHostName('api.example.com');
|
||||
if (apiHost) {
|
||||
console.log(`API proxying to ${apiHost.destination}:${apiHost.destinationPort}`);
|
||||
}
|
||||
```
|
||||
|
||||
### Removing Hosts
|
||||
|
||||
```typescript
|
||||
const hostToRemove = nginx.getDeployedNginxHostByHostName('staging.myapp.com');
|
||||
if (hostToRemove) {
|
||||
await nginx.removeDeployedHost(hostToRemove);
|
||||
// Nginx automatically reloaded with updated config
|
||||
}
|
||||
```
|
||||
|
||||
### Stopping Nginx
|
||||
|
||||
```typescript
|
||||
// Gracefully stop the Nginx process
|
||||
await nginx.stop();
|
||||
```
|
||||
|
||||
## Generated Configuration
|
||||
|
||||
SmartNginx generates production-ready Nginx configurations:
|
||||
|
||||
**For each host, you get:**
|
||||
- HTTP (port 80) → HTTPS (port 443) automatic redirect
|
||||
- Upstream with keepalive connections (100 idle connections)
|
||||
- WebSocket-friendly proxy settings (HTTP/1.1, no buffering)
|
||||
- Proper proxy headers (`X-Real-IP`, `X-Forwarded-For`, `X-Forwarded-Proto`)
|
||||
- Smart failover (`proxy_next_upstream` on errors, timeouts, 404/429/500/502)
|
||||
|
||||
**Default server:**
|
||||
- Self-signed certificate for unmatched domains
|
||||
- Redirects to your configured `defaultProxyUrl`
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ SmartNginx │
|
||||
├─────────────────────────────────────────────────────────────┤
|
||||
│ hostCandidates[] → deploy() → deployedHosts[] │
|
||||
│ ↓ │
|
||||
│ NginxProcess │
|
||||
│ (start/reload/stop) │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
↓
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ Generated Files │
|
||||
├─────────────────────────────────────────────────────────────┤
|
||||
│ nginxconfig/ │
|
||||
│ ├── nginx.conf (main config) │
|
||||
│ └── hosts/ │
|
||||
│ ├── default.private.pem (self-signed key) │
|
||||
│ ├── default.public.pem (self-signed cert) │
|
||||
│ ├── api.example.com.conf │
|
||||
│ ├── api.example.com.private.pem │
|
||||
│ └── api.example.com.public.pem │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### SmartNginx
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `addHostCandidate(config)` | Add a new host configuration |
|
||||
| `deploy()` | Write configs and start/reload Nginx |
|
||||
| `listDeployedHosts()` | Get all currently deployed hosts |
|
||||
| `getDeployedNginxHostByHostName(hostname)` | Find a host by domain name |
|
||||
| `removeDeployedHost(host)` | Remove a host and reload Nginx |
|
||||
| `stop()` | Gracefully stop Nginx |
|
||||
|
||||
### IHostConfig
|
||||
|
||||
```typescript
|
||||
interface IHostConfig {
|
||||
hostName: string; // Domain name (e.g., 'api.example.com')
|
||||
destination: string; // Backend server IP/hostname
|
||||
destinationPort: number; // Backend port
|
||||
privateKey: string; // SSL private key (PEM)
|
||||
publicKey: string; // SSL certificate (PEM)
|
||||
}
|
||||
```
|
||||
|
||||
### NginxHost
|
||||
|
||||
Each host instance exposes:
|
||||
- `hostName` - The configured domain
|
||||
- `destination` - Backend address
|
||||
- `destinationPort` - Backend port
|
||||
- `configString` - The generated Nginx config (after deploy)
|
||||
- `deploy()` - Write this host's config files
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@@ -1,2 +0,0 @@
|
||||
import "typings-test";
|
||||
import "should";
|
||||
27
test/test.js
27
test/test.js
@@ -1,27 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
require("should");
|
||||
var smartnginx = require("../dist/index");
|
||||
describe("smartnginx", function () {
|
||||
var testNginxConfig;
|
||||
var testNginxZone01;
|
||||
var testNginxZone02;
|
||||
describe("NginxZone", function () {
|
||||
it("\"new NginxZone()\" should produce an instance of NginxConfig", function () {
|
||||
testNginxZone01 = new smartnginx.NginxZone({
|
||||
zoneName: "test1.bleu.de",
|
||||
type: smartnginx.zoneTypes.reverseProxy,
|
||||
destination: "192.192.192.192"
|
||||
});
|
||||
testNginxZone01.should.be.instanceof(smartnginx.NginxZone);
|
||||
console.log(testNginxZone01.configString);
|
||||
});
|
||||
});
|
||||
describe("NginxConfig", function () {
|
||||
it("\"new NginxConfig()\" should produce an instance of NginxConfig", function () {
|
||||
testNginxConfig = new smartnginx.NginxConfig();
|
||||
testNginxConfig.should.be.instanceof(smartnginx.NginxConfig);
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQixJQUFZLFVBQVUsV0FBTSxlQUFlLENBQUMsQ0FBQTtBQUU1QyxRQUFRLENBQUMsWUFBWSxFQUFDO0lBQ2xCLElBQUksZUFBc0MsQ0FBQztJQUMzQyxJQUFJLGVBQW9DLENBQUM7SUFDekMsSUFBSSxlQUFvQyxDQUFDO0lBQ3pDLFFBQVEsQ0FBQyxXQUFXLEVBQUM7UUFDakIsRUFBRSxDQUFDLCtEQUE2RCxFQUFDO1lBQzdELGVBQWUsR0FBRyxJQUFJLFVBQVUsQ0FBQyxTQUFTLENBQUM7Z0JBQ3ZDLFFBQVEsRUFBQyxlQUFlO2dCQUN4QixJQUFJLEVBQUMsVUFBVSxDQUFDLFNBQVMsQ0FBQyxZQUFZO2dCQUN0QyxXQUFXLEVBQUMsaUJBQWlCO2FBQ2hDLENBQUMsQ0FBQztZQUNILGVBQWUsQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxVQUFVLENBQUMsU0FBUyxDQUFDLENBQUM7WUFDM0QsT0FBTyxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUMsWUFBWSxDQUFDLENBQUM7UUFDOUMsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDLENBQUMsQ0FBQztJQUNILFFBQVEsQ0FBQyxhQUFhLEVBQUM7UUFDbkIsRUFBRSxDQUFDLGlFQUErRCxFQUFDO1lBQy9ELGVBQWUsR0FBRyxJQUFJLFVBQVUsQ0FBQyxXQUFXLEVBQUUsQ0FBQztZQUMvQyxlQUFlLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsVUFBVSxDQUFDLFdBQVcsQ0FBQyxDQUFDO1FBQ2pFLENBQUMsQ0FBQyxDQUFDO0lBQ1AsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyJ9
|
||||
76
test/test.ts
76
test/test.ts
@@ -1,26 +1,54 @@
|
||||
import "typings-test";
|
||||
import "should";
|
||||
import * as smartnginx from "../dist/index";
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import * as path from 'node:path';
|
||||
|
||||
describe("smartnginx",function(){
|
||||
let testNginxConfig:smartnginx.NginxConfig;
|
||||
let testNginxZone01:smartnginx.NginxZone;
|
||||
let testNginxZone02:smartnginx.NginxZone;
|
||||
describe("NginxZone",function(){
|
||||
it(`"new NginxZone()" should produce an instance of NginxConfig`,function(){
|
||||
testNginxZone01 = new smartnginx.NginxZone({
|
||||
zoneName:"test1.bleu.de",
|
||||
type:smartnginx.zoneTypes.reverseProxy,
|
||||
destination:"192.192.192.192"
|
||||
});
|
||||
testNginxZone01.should.be.instanceof(smartnginx.NginxZone);
|
||||
console.log(testNginxZone01.configString);
|
||||
});
|
||||
});
|
||||
describe("NginxConfig",function(){
|
||||
it(`"new NginxConfig()" should produce an instance of NginxConfig`,function(){
|
||||
testNginxConfig = new smartnginx.NginxConfig();
|
||||
testNginxConfig.should.be.instanceof(smartnginx.NginxConfig);
|
||||
});
|
||||
});
|
||||
import { Qenv } from '@push.rocks/qenv';
|
||||
|
||||
import * as smartnginx from '../ts/index.js';
|
||||
|
||||
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).toBeInstanceOf(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).toBeInstanceOf(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();
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
|
||||
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartnginx',
|
||||
version: '2.0.53',
|
||||
description: 'A TypeScript library for controlling Nginx from Node.js, with support for generating and managing Nginx configurations dynamically.'
|
||||
}
|
||||
11
ts/index.ts
11
ts/index.ts
@@ -1,9 +1,4 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as CommandModule from "./smartnginx.command";
|
||||
|
||||
// classes
|
||||
export {NginxConfig} from "./smartnginx.classes.nginxconfig";
|
||||
export {NginxZone,zoneTypes} from "./smartnginx.classes.nginxzone";
|
||||
|
||||
// exports
|
||||
export let command = CommandModule;
|
||||
export * from './smartnginx.classes.smartnginx.js';
|
||||
export * from './smartnginx.classes.nginxprocess.js';
|
||||
export * from './smartnginx.classes.nginxhost.js';
|
||||
|
||||
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,46 +0,0 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as paths from "./smartnginx.paths";
|
||||
import * as command from "./smartnginx.command";
|
||||
import * as snippets from "./smartnginx.snippets"
|
||||
import {NginxZone} from "./smartnginx.classes.nginxzone";
|
||||
let allConfigs:NginxConfig[] = [];
|
||||
|
||||
export class NginxConfig {
|
||||
zones:NginxZone[];
|
||||
isDeployed:boolean = false;
|
||||
constructor(){
|
||||
|
||||
};
|
||||
|
||||
// interact with Zones
|
||||
addZone(zoneArg:NginxZone){
|
||||
|
||||
}
|
||||
listZones():NginxZone[] {
|
||||
return this.zones;
|
||||
};
|
||||
removeZones(zoneArg:NginxZone){
|
||||
|
||||
}
|
||||
|
||||
// handle deployment of zones
|
||||
deploy(nginxRestartArg:boolean = false){
|
||||
plugins.smartfile.fs.remove(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDir(paths.nginxConfigBase);
|
||||
for(let config of allConfigs){
|
||||
config.isDeployed = false;
|
||||
};
|
||||
this.isDeployed = true;
|
||||
for(let zone of this.zones){
|
||||
zone.deploy();
|
||||
};
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
snippets.getBaseConfigString(),
|
||||
plugins.path.join(paths.nginxConfigBase,"nginx.conf")
|
||||
);
|
||||
if(nginxRestartArg){
|
||||
command.restart(this);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
62
ts/smartnginx.classes.nginxhost.ts
Normal file
62
ts/smartnginx.classes.nginxhost.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import * as plugins from './smartnginx.plugins.js';
|
||||
import * as paths from './smartnginx.paths.js';
|
||||
import * as snippets from './smartnginx.snippets.js';
|
||||
|
||||
import { SmartNginx } from './smartnginx.classes.smartnginx.js';
|
||||
|
||||
import { type IHostConfig } from './interfaces/hostconfig.js';
|
||||
|
||||
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
|
||||
);
|
||||
await plugins.fs.file(filePathConfig).write(this.configString);
|
||||
|
||||
// write ssl
|
||||
await plugins.fs.file(filePathPrivate).write(this.privateKey);
|
||||
await plugins.fs.file(filePathPublic).write(this.publicKey);
|
||||
}
|
||||
}
|
||||
67
ts/smartnginx.classes.nginxprocess.ts
Normal file
67
ts/smartnginx.classes.nginxprocess.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import * as plugins from './smartnginx.plugins.js';
|
||||
import * as paths from './smartnginx.paths.js';
|
||||
import { SmartNginx } from './smartnginx.classes.smartnginx.js';
|
||||
import { NginxHost } from './smartnginx.classes.nginxhost.js';
|
||||
|
||||
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 plugins.smartshell.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;
|
||||
console.log('info', 'started Nginx!');
|
||||
}
|
||||
|
||||
/**
|
||||
* reload config
|
||||
*/
|
||||
public async reloadConfig() {
|
||||
if (!this.started) {
|
||||
this.start();
|
||||
} else {
|
||||
await this.smartshellInstance.exec('nginx -s reload');
|
||||
}
|
||||
this.smartNginxRef.logger.log('info', 'NginxProcess has loaded the new config!');
|
||||
}
|
||||
|
||||
/**
|
||||
* stop the nginx instance
|
||||
*/
|
||||
public async stop() {
|
||||
if (this.nginxChildProcess) {
|
||||
this.smartshellInstance.exec('nginx -s quit');
|
||||
this.started = false;
|
||||
this.smartNginxRef.logger.log('info', 'stopped Nginx!');
|
||||
} else {
|
||||
this.smartNginxRef.logger.log('info', 'nginx already stopped!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
public check(): boolean {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as paths from "./smartnginx.paths";
|
||||
import * as command from "./smartnginx.command";
|
||||
import * as snippets from "./smartnginx.snippets"
|
||||
export enum zoneTypes {
|
||||
reverseProxy,
|
||||
static
|
||||
}
|
||||
|
||||
export class NginxZone {
|
||||
zoneName:string; // the zone name e.g. domain name
|
||||
configString:string; // the actual zone config file as string
|
||||
constructor(optionsArg:{
|
||||
zoneName:string,
|
||||
type:zoneTypes,
|
||||
destination:string
|
||||
}){
|
||||
this.configString = snippets.getZoneConfigString(optionsArg.zoneName,optionsArg.destination);
|
||||
};
|
||||
deploy(){
|
||||
let filePath = plugins.path.join(paths.nginxZoneBase,this.zoneName + ".conf");
|
||||
plugins.smartfile.memory.toFsSync(this.configString,filePath);
|
||||
};
|
||||
};
|
||||
157
ts/smartnginx.classes.smartnginx.ts
Normal file
157
ts/smartnginx.classes.smartnginx.ts
Normal file
@@ -0,0 +1,157 @@
|
||||
import * as plugins from './smartnginx.plugins.js';
|
||||
import * as paths from './smartnginx.paths.js';
|
||||
import * as snippets from './smartnginx.snippets.js';
|
||||
import { NginxHost } from './smartnginx.classes.nginxhost.js';
|
||||
import { NginxProcess } from './smartnginx.classes.nginxprocess.js';
|
||||
import { type IHostConfig } from './interfaces/hostconfig.js';
|
||||
|
||||
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 = new plugins.smartlog.Smartlog({
|
||||
logContext: null
|
||||
}));
|
||||
}
|
||||
|
||||
// ===================
|
||||
// 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.findSync((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
|
||||
await plugins.fs.directory(paths.nginxConfigDirPath).recursive().create();
|
||||
await plugins.fs.file(paths.nginxConfFile).write(
|
||||
snippets.getBaseConfigString(this.options.defaultProxyUrl)
|
||||
);
|
||||
|
||||
// write standard self signed certificate
|
||||
const selfsignedCert = plugins.selfsigned.generate(
|
||||
[{ name: 'commonName', value: 'selfsigned.git.zone' }],
|
||||
{ days: 365 }
|
||||
);
|
||||
|
||||
// deploy hosts
|
||||
await plugins.fs.directory(paths.nginxHostDirPath).recursive().create();
|
||||
await plugins.fs.file(
|
||||
plugins.path.join(paths.nginxHostDirPath, './default.private.pem')
|
||||
).write(selfsignedCert.private);
|
||||
await plugins.fs.file(
|
||||
plugins.path.join(paths.nginxHostDirPath, './default.public.pem')
|
||||
).write(selfsignedCert.cert);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import {NginxConfig} from "./smartnginx.classes.nginxconfig";
|
||||
import {NginxZone} from "./smartnginx.classes.nginxzone";
|
||||
|
||||
/**
|
||||
* starts nginx
|
||||
*/
|
||||
export let start = (configArg:NginxConfig) => {
|
||||
|
||||
};
|
||||
|
||||
export let restart = (configArg:NginxConfig) => {
|
||||
stop();
|
||||
start(configArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* stops nginx
|
||||
*/
|
||||
export let stop = () => {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
export let check = ():boolean => {
|
||||
return;
|
||||
};
|
||||
@@ -1,5 +1,9 @@
|
||||
import * as plugins from "./smartnginx.plugins"
|
||||
import * as plugins from './smartnginx.plugins.js';
|
||||
|
||||
export let packageBase = plugins.path.join(__dirname,"../");
|
||||
export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig/");
|
||||
export let nginxZoneBase = plugins.path.join(nginxConfigBase,"zones");
|
||||
// directories
|
||||
export const packageBase = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
|
||||
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,7 +1,25 @@
|
||||
import "typings-global";
|
||||
export import cert = require("cert");
|
||||
export import path = require("path");
|
||||
export import q = require("q");
|
||||
export let shelljs = require("shelljs");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartstring = require("smartstring");
|
||||
// native
|
||||
import * as path from 'node:path';
|
||||
|
||||
export { path };
|
||||
|
||||
// @push.rocks scope
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartfs from '@push.rocks/smartfs';
|
||||
import * as smartlog from '@push.rocks/smartlog';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
import * as smartstring from '@push.rocks/smartstring';
|
||||
import * as smartunique from '@push.rocks/smartunique';
|
||||
|
||||
export { lik, smartfs, smartlog, smartpath, smartpromise, smartshell, smartstring, smartunique };
|
||||
|
||||
// Shared filesystem instance
|
||||
const fsProvider = new smartfs.SmartFsProviderNode();
|
||||
export const fs = new smartfs.SmartFs(fsProvider);
|
||||
|
||||
// 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.js';
|
||||
import * as paths from './smartnginx.paths.js';
|
||||
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,41 +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;
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user