Compare commits
No commits in common. "master" and "v1.0.6" have entirely different histories.
@ -1,66 +0,0 @@
|
||||
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
|
@ -1,124 +0,0 @@
|
||||
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
|
23
.gitignore
vendored
23
.gitignore
vendored
@ -1,20 +1,5 @@
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
nginxconfig/
|
||||
coverage/
|
||||
docs/
|
||||
.nogit/
|
110
.gitlab-ci.yml
110
.gitlab-ci.yml
@ -1,119 +1,27 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
before_script:
|
||||
- "apt-get update && apt-get install nginx -y"
|
||||
|
||||
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:
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
- npmci test stable
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
environment: npmjs-com_registry
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
- npmci 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
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@ -1,11 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
26
.vscode/settings.json
vendored
@ -1,26 +0,0 @@
|
||||
{
|
||||
"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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
27
README.md
Normal file
27
README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# smartnginx
|
||||
control nginx from node, TypeScript ready
|
||||
|
||||
## Status
|
||||
[](https://gitlab.com/pushrocks/smartnginx/commits/master)
|
||||
|
||||
## Features
|
||||
|
||||
* easy reverse configuration
|
||||
* automatic letsencrypt DNS01 challenge based ssl cert generation
|
||||
* automatic nginx process handling zero-downtime config reloading
|
||||
* works in Docker environements
|
||||
|
||||
## Usage
|
||||
We recommend the use of TypeScript! :)
|
||||
|
||||
```typescript
|
||||
import * as smartnginx from "smartnginx";
|
||||
myNginxConfig = new smartnginx.NginxConfig();
|
||||
myNginxZone = new smartnginx.NginxZone({
|
||||
zoneName:"some.example.com",
|
||||
type:"reverseProxy",
|
||||
destination:"192.192.192.192" // some destination IP
|
||||
});
|
||||
myNginxConfig.addZone(myNginxZone); // adds the zone to the config
|
||||
myNginxConfig.deploy(); // deploys the referenced NginxConfig and gracefully reloads it
|
||||
```
|
3
dist/index.d.ts
vendored
Normal file
3
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export * from "./smartnginx.classes.nginxconfig";
|
||||
export * from "./smartnginx.classes.nginxprocess";
|
||||
export * from "./smartnginx.classes.nginxhost";
|
9
dist/index.js
vendored
Normal file
9
dist/index.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
// classes
|
||||
__export(require("./smartnginx.classes.nginxconfig"));
|
||||
__export(require("./smartnginx.classes.nginxprocess"));
|
||||
__export(require("./smartnginx.classes.nginxhost"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsVUFBVTtBQUNWLGlCQUFjLGtDQUFrQyxDQUFDLEVBQUE7QUFDakQsaUJBQWMsbUNBQW1DLENBQUMsRUFBQTtBQUNsRCxpQkFBYyxnQ0FBZ0MsQ0FBQyxFQUFBIn0=
|
19
dist/smartnginx.classes.nginxconfig.d.ts
vendored
Normal file
19
dist/smartnginx.classes.nginxconfig.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import { NginxHost } from "./smartnginx.classes.nginxhost";
|
||||
import { NginxProcess } from "./smartnginx.classes.nginxprocess";
|
||||
/**
|
||||
* main class that manages a NginxInstance
|
||||
*/
|
||||
export declare class NginxConfig {
|
||||
hosts: NginxHost[];
|
||||
cert: plugins.cert.Cert;
|
||||
nginxProcess: NginxProcess;
|
||||
isDeployed: boolean;
|
||||
constructor(optionsArg: plugins.cert.ICertConstructorOptions);
|
||||
addHost(nginxHostArg: NginxHost): void;
|
||||
listHosts(): NginxHost[];
|
||||
removeHost(nginxHostArg: NginxHost): void;
|
||||
clean(): void;
|
||||
deploy(): plugins.q.Promise<{}>;
|
||||
}
|
71
dist/smartnginx.classes.nginxconfig.js
vendored
Normal file
71
dist/smartnginx.classes.nginxconfig.js
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
"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 = [];
|
||||
/**
|
||||
* main class that manages a NginxInstance
|
||||
*/
|
||||
class NginxConfig {
|
||||
constructor(optionsArg) {
|
||||
this.hosts = [];
|
||||
this.nginxProcess = new smartnginx_classes_nginxprocess_1.NginxProcess(this);
|
||||
this.isDeployed = false;
|
||||
this.cert = new plugins.cert.Cert({
|
||||
cfEmail: optionsArg.cfEmail,
|
||||
cfKey: optionsArg.cfKey,
|
||||
sslDir: paths.nginxCertBase,
|
||||
gitOriginRepo: optionsArg.gitOriginRepo,
|
||||
testMode: optionsArg.testMode
|
||||
});
|
||||
}
|
||||
;
|
||||
// interact with Hosts
|
||||
addHost(nginxHostArg) {
|
||||
this.hosts.push(nginxHostArg);
|
||||
}
|
||||
listHosts() {
|
||||
return this.hosts;
|
||||
}
|
||||
;
|
||||
removeHost(nginxHostArg) {
|
||||
}
|
||||
clean() {
|
||||
this.hosts = [];
|
||||
}
|
||||
// handle deployment of hosts
|
||||
deploy() {
|
||||
let done = plugins.q.defer();
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxHostFileBase);
|
||||
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 hosts
|
||||
let promiseArray = [];
|
||||
for (let host of this.hosts) {
|
||||
let hostDeployedPromise = host.deploy(this.cert);
|
||||
hostDeployedPromise.then(() => {
|
||||
plugins.beautylog.info(`Host ${host.hostName} deployed!`);
|
||||
this.nginxProcess.reloadConfig();
|
||||
});
|
||||
promiseArray.push(hostDeployedPromise);
|
||||
}
|
||||
;
|
||||
plugins.q.all(promiseArray)
|
||||
.then(() => {
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.NginxConfig = NginxConfig;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uI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FDLEtBQUssQ0FBQyxDQUFDLENBQUM7WUFDMUIsSUFBSSxtQkFBbUIsR0FBRyxJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQztZQUNqRCxtQkFBbUIsQ0FBQyxJQUFJLENBQUM7Z0JBQ3JCLE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLFFBQVEsSUFBSSxDQUFDLFFBQVEsWUFBWSxDQUFDLENBQUM7Z0JBQzFELElBQUksQ0FBQyxZQUFZLENBQUMsWUFBWSxFQUFFLENBQUM7WUFDckMsQ0FBQyxDQUFDLENBQUM7WUFDSCxZQUFZLENBQUMsSUFBSSxDQUFDLG1CQUFtQixDQUFDLENBQUM7UUFDM0MsQ0FBQztRQUFBLENBQUM7UUFDRixPQUFPLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUM7YUFDdEIsSUFBSSxDQUFDO1lBQ0YsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ25CLENBQUMsQ0FBQyxDQUFDO1FBRVAsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFDTCxDQUFDO0FBNURZLG1CQUFXLGNBNER2QixDQUFBO0FBQUEsQ0FBQyJ9
|
25
dist/smartnginx.classes.nginxhost.d.ts
vendored
Normal file
25
dist/smartnginx.classes.nginxhost.d.ts
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
/**
|
||||
* the host config data that NginxHost needs to create a valid instance
|
||||
*/
|
||||
export interface IHostConfigData {
|
||||
hostName: string;
|
||||
type: hostTypes;
|
||||
destination: string;
|
||||
}
|
||||
export declare enum hostTypes {
|
||||
reverseProxy = 0,
|
||||
static = 1,
|
||||
}
|
||||
/**
|
||||
* manages a single nginx host
|
||||
*/
|
||||
export declare class NginxHost {
|
||||
hostName: string;
|
||||
type: hostTypes;
|
||||
destination: string;
|
||||
configString: string;
|
||||
constructor(optionsArg: IHostConfigData);
|
||||
deploy(certInstanceArg: plugins.cert.Cert): plugins.q.Promise<{}>;
|
||||
}
|
35
dist/smartnginx.classes.nginxhost.js
vendored
Normal file
35
dist/smartnginx.classes.nginxhost.js
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
const paths = require("./smartnginx.paths");
|
||||
const snippets = require("./smartnginx.snippets");
|
||||
(function (hostTypes) {
|
||||
hostTypes[hostTypes["reverseProxy"] = 0] = "reverseProxy";
|
||||
hostTypes[hostTypes["static"] = 1] = "static";
|
||||
})(exports.hostTypes || (exports.hostTypes = {}));
|
||||
var hostTypes = exports.hostTypes;
|
||||
/**
|
||||
* manages a single nginx host
|
||||
*/
|
||||
class NginxHost {
|
||||
constructor(optionsArg) {
|
||||
this.hostName = optionsArg.hostName;
|
||||
this.type = optionsArg.type;
|
||||
this.destination = optionsArg.destination;
|
||||
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
|
||||
}
|
||||
;
|
||||
deploy(certInstanceArg) {
|
||||
let done = plugins.q.defer();
|
||||
let filePath = plugins.path.join(paths.nginxHostFileBase, this.hostName + ".conf");
|
||||
// writeConfig
|
||||
plugins.smartfile.memory.toFsSync(this.configString, filePath);
|
||||
// get cert
|
||||
certInstanceArg.getDomainCert(this.hostName)
|
||||
.then(done.resolve);
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.NginxHost = NginxHost;
|
||||
;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54aG9zdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguY2xhc3Nlcy5uZ2lueGhvc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5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RQUMvRCxXQUFXO1FBQ1gsZUFBZSxDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDO2FBQ3ZDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDeEIsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFDTCxDQUFDO0FBckJZLGlCQUFTLFlBcUJyQixDQUFBO0FBQUEsQ0FBQyJ9
|
29
dist/smartnginx.classes.nginxprocess.d.ts
vendored
Normal file
29
dist/smartnginx.classes.nginxprocess.d.ts
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="q" />
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
|
||||
/**
|
||||
* manages a nginxprocess for an NginxConfig
|
||||
*/
|
||||
export declare class NginxProcess {
|
||||
started: boolean;
|
||||
nginxConfig: NginxConfig;
|
||||
nginxChildProcess: plugins.childProcess.ChildProcess;
|
||||
constructor(nginxConfigArg: any);
|
||||
/**
|
||||
* start nginx
|
||||
*/
|
||||
start(): plugins.q.Promise<{}>;
|
||||
/**
|
||||
* reload config
|
||||
*/
|
||||
reloadConfig(): plugins.q.Promise<{}>;
|
||||
/**
|
||||
* stop the nginx instance
|
||||
*/
|
||||
stop(): plugins.q.Promise<{}>;
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
check(): boolean;
|
||||
}
|
79
dist/smartnginx.classes.nginxprocess.js
vendored
Normal file
79
dist/smartnginx.classes.nginxprocess.js
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
const paths = require("./smartnginx.paths");
|
||||
/**
|
||||
* manages a nginxprocess for an NginxConfig
|
||||
*/
|
||||
class NginxProcess {
|
||||
constructor(nginxConfigArg) {
|
||||
this.started = false;
|
||||
this.nginxConfig = nginxConfigArg;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* start nginx
|
||||
*/
|
||||
start() {
|
||||
let done = plugins.q.defer();
|
||||
if (typeof this.nginxChildProcess == "undefined") {
|
||||
this.nginxChildProcess = plugins.childProcess.exec(`nginx -c ${paths.nginxConfFile}`, function (error, stdout, stderr) {
|
||||
console.log(`stdout: ${stdout}`);
|
||||
console.log(`stderr: ${stderr}`);
|
||||
if (error !== null) {
|
||||
console.log(`exec error: ${error}`);
|
||||
}
|
||||
;
|
||||
});
|
||||
}
|
||||
;
|
||||
this.started = true;
|
||||
plugins.beautylog.info("started Nginx!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* reload config
|
||||
*/
|
||||
reloadConfig() {
|
||||
let done = plugins.q.defer();
|
||||
if (this.started == false) {
|
||||
this.start();
|
||||
}
|
||||
else {
|
||||
plugins.shelljs.exec("nginx -s reload");
|
||||
}
|
||||
;
|
||||
plugins.beautylog.ok("NginxProcess has loaded the new config!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* stop the nginx instance
|
||||
*/
|
||||
stop() {
|
||||
let done = plugins.q.defer();
|
||||
if (typeof this.nginxChildProcess != "undefined") {
|
||||
plugins.shelljs.exec("nginx -s quit");
|
||||
this.started = false;
|
||||
plugins.beautylog.info("stopped Nginx!");
|
||||
}
|
||||
else {
|
||||
plugins.beautylog.log("nginx already stopped!");
|
||||
}
|
||||
;
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
}
|
||||
;
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
check() {
|
||||
return;
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.NginxProcess = NginxProcess;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54cHJvY2Vzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJz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9BQU8sR0FBRyxLQUFLLENBQUM7WUFDckIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztRQUM3QyxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyx3QkFBd0IsQ0FBQyxDQUFDO1FBQ3BELENBQUM7UUFBQSxDQUFDO1FBQ0YsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ2YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7SUFFRDs7T0FFRztJQUNILEtBQUs7UUFDRCxNQUFNLENBQUM7SUFDWCxDQUFDOztBQUNMLENBQUM7QUFqRVksb0JBQVksZUFpRXhCLENBQUEifQ==
|
5
dist/smartnginx.paths.d.ts
vendored
Normal file
5
dist/smartnginx.paths.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
export declare let packageBase: string;
|
||||
export declare let nginxConfigBase: string;
|
||||
export declare let nginxHostFileBase: string;
|
||||
export declare let nginxCertBase: string;
|
||||
export declare let nginxConfFile: string;
|
10
dist/smartnginx.paths.js
vendored
Normal file
10
dist/smartnginx.paths.js
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
// directories
|
||||
exports.packageBase = plugins.path.join(__dirname, "../");
|
||||
exports.nginxConfigBase = plugins.path.join(exports.packageBase, "nginxconfig");
|
||||
exports.nginxHostFileBase = plugins.path.join(exports.nginxConfigBase, "hosts");
|
||||
exports.nginxCertBase = plugins.path.join(exports.nginxConfigBase, "cert");
|
||||
// files
|
||||
exports.nginxConfFile = plugins.path.join(exports.nginxConfigBase, "nginx.conf");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUd6QixDQUFDLENBSDhDO0FBRS9DLGNBQWM7QUFDSCxtQkFBVyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxLQUFLLENBQUMsQ0FBQztBQUNqRCx1QkFBZSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLG1CQUFXLEVBQUMsYUFBYSxDQUFDLENBQUM7QUFDL0QseUJBQWlCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsdUJBQWUsRUFBQyxPQUFPLENBQUMsQ0FBQztBQUMvRCxxQkFBYSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHVCQUFlLEVBQUMsTUFBTSxDQUFDLENBQUM7QUFFckUsUUFBUTtBQUNHLHFCQUFhLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsdUJBQWUsRUFBQyxZQUFZLENBQUMsQ0FBQyJ9
|
9
dist/smartnginx.plugins.d.ts
vendored
Normal file
9
dist/smartnginx.plugins.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import cert = require("cert");
|
||||
export import childProcess = require("child_process");
|
||||
export import path = require("path");
|
||||
export import q = require("q");
|
||||
export import shelljs = require("shelljs");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartstring = require("smartstring");
|
11
dist/smartnginx.plugins.js
vendored
Normal file
11
dist/smartnginx.plugins.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.cert = require("cert");
|
||||
exports.childProcess = require("child_process");
|
||||
exports.path = require("path");
|
||||
exports.q = require("q");
|
||||
exports.shelljs = require("shelljs");
|
||||
exports.smartfile = require("smartfile");
|
||||
exports.smartstring = require("smartstring");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDVixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixvQkFBWSxXQUFXLGVBQWUsQ0FBQyxDQUFDO0FBQ3hDLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixTQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDakIsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFDO0FBQzdCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsbUJBQVcsV0FBVyxhQUFhLENBQUMsQ0FBQyJ9
|
2
dist/smartnginx.snippets.d.ts
vendored
Normal file
2
dist/smartnginx.snippets.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export declare let getBaseConfigString: () => string;
|
||||
export declare let getHostConfigString: (hostNameArg: string, destinationIpArg: string) => string;
|
103
dist/smartnginx.snippets.js
vendored
Normal file
103
dist/smartnginx.snippets.js
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartnginx.plugins");
|
||||
const paths = require("./smartnginx.paths");
|
||||
exports.getBaseConfigString = () => {
|
||||
let baseConfig = plugins.smartstring.indent.normalize(`
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
# multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
server_names_hash_bucket_size 128;
|
||||
|
||||
##
|
||||
# Basic Settings
|
||||
##
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
# server_tokens off;
|
||||
|
||||
# server_names_hash_bucket_size 64;
|
||||
# server_name_in_redirect off;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
##
|
||||
# SSL Settings
|
||||
##
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
##
|
||||
# Logging Settings
|
||||
##
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
##
|
||||
# Gzip Settings
|
||||
##
|
||||
|
||||
gzip on;
|
||||
gzip_disable "msie6";
|
||||
|
||||
# gzip_vary on;
|
||||
# gzip_proxied any;
|
||||
# gzip_comp_level 6;
|
||||
# gzip_buffers 16 8k;
|
||||
# gzip_http_version 1.1;
|
||||
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
##
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include ${paths.nginxHostFileBase}/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
daemon off;
|
||||
`);
|
||||
return baseConfig;
|
||||
};
|
||||
exports.getHostConfigString = (hostNameArg, destinationIpArg) => {
|
||||
let hostConfig = plugins.smartstring.indent.normalize(`
|
||||
upstream ${hostNameArg} {
|
||||
server ${destinationIpArg};
|
||||
}
|
||||
|
||||
server {
|
||||
listen *:80 ;
|
||||
server_name ${hostNameArg};
|
||||
rewrite ^ https://${hostNameArg}$request_uri? permanent;
|
||||
}
|
||||
|
||||
server {
|
||||
listen *:443 ssl;
|
||||
server_name ${hostNameArg};
|
||||
ssl_certificate ${paths.nginxCertBase}/${hostNameArg}/fullchain.pem;
|
||||
ssl_certificate_key ${paths.nginxCertBase}/${hostNameArg}/privkey.pem;
|
||||
|
||||
location / {
|
||||
proxy_pass http://${hostNameArg};
|
||||
include /etc/nginx/proxy_params;
|
||||
}
|
||||
location ~ /\.git {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
`);
|
||||
return hostConfig;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5zbmlwcGV0cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbnguc25pcHBldHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFDaEQsTUFBWSxLQUFLLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUNqQywyQkFBbUIsR0FBRztJQUNoQyxJQUFJLFVBQVUsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLE1BQU0sQ0FBQyxTQUFTLENBQUM7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O2FBOEQxQyxLQUFLLENBQUMsaUJBQWlCOzs7O0VBSWxDLENBQUMsQ0FBQztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUM7QUFDbkIsQ0FBQyxDQUFBO0FBR1UsMkJBQW1CLEdBQUcsQ0FBQyxXQUFrQixFQUFDLGdCQUF1QjtJQUMzRSxJQUFJLFVBQVUsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLE1BQU0sQ0FBQyxTQUFTLENBQUM7YUFDMUMsV0FBVztZQUNaLGdCQUFnQjs7Ozs7a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Ca3QJABo8fEGIy/g7M5OB5euLHQLvCvYJDn9YWAryhRedR1B2e
|
||||
zEZOO0qxUJSjMdnYFYG6Na/poM3atnJ4W8pJzOtA4w==
|
||||
-----END RSA PRIVATE KEY-----
|
@ -1,6 +0,0 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCHoQbEbAo/0ZDFU9AkubBRi8Fe
|
||||
KdhCFrzK+wXZD9JnEJRa3q6oCI+6H3YLYleGGP8Vkwca8ykz5BX0MrKAlZWpoEpq
|
||||
gm2lVCBKh9mqCG1bN0aPdlwhE24/HZFbeVgyJBvH/7XZJDGlm638dSMoXMmPtwLf
|
||||
q1uTAmHwtHBEqdiLFwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
@ -1,15 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXQIBAAKBgQD5b6wtr4xHY5gxH0SR+V9XIQPH6DGe2PXlKWN02dgvg7Ej/4uA
|
||||
7MmOnem2SUpWE2GwuKCAUCeZkj+riEmky0EWFexaM3BmcvWLSHZ6MAYg5FxTsUG8
|
||||
IXxNYUdTPpUBxaCX/yp/dvpiDqSMH67y9LwI85oWHx/zk1jMixaZXvOCXwIDAQAB
|
||||
AoGBALFXn1/f9uluuu753yO12/4zf9+qi1T3xmQGuCqFE7o8dD422vVv5KHcTiUH
|
||||
GK34G7Wsnph75JvAKjqHrGxZAk0NN59VK4Sl141S7qzXgjQf5Ks7r5y8v8AQgvEM
|
||||
zOwutOqlGNHJZ1NlCDJuMNxUe/vyRXRl1WDCeJF6pt8huZgRAkEA/Ppqz8NyU+B7
|
||||
kaz3e39uCELsyaDl3Xf82JMmJASBlndso3l3H2ihihAMYHaH21IxKQnfaiKMyfK4
|
||||
tvONLB/eZwJBAPxqbKEzLqYM7ds8QG2fty7heIcwtcKjTMThl99/OinNsJdd0DUE
|
||||
GPBVaDlvqijEk5R4oQ5CkzrQDe6mVk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
tNQngsMDf+PZQMLm2bT1Pxk2KXd0rFMkVWprcRs2qx3Yz0Q=
|
||||
-----END CERTIFICATE-----
|
@ -1,31 +0,0 @@
|
||||
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/HC_Volume_11396573/lossless/push.rocks/smartnginx/nginxconfig/hosts/test100.bleu.de.public.pem;
|
||||
ssl_certificate_key /mnt/HC_Volume_11396573/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 +0,0 @@
|
||||
some private
|
@ -1 +0,0 @@
|
||||
some public
|
@ -1,31 +0,0 @@
|
||||
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/HC_Volume_11396573/lossless/push.rocks/smartnginx/nginxconfig/hosts/test102.bleu.de.public.pem;
|
||||
ssl_certificate_key /mnt/HC_Volume_11396573/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 +0,0 @@
|
||||
some private
|
@ -1 +0,0 @@
|
||||
some public
|
@ -1,79 +0,0 @@
|
||||
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 /mnt/HC_Volume_11396573/lossless/push.rocks/smartnginx/nginxconfig/hosts/default.public.pem;
|
||||
ssl_certificate_key /mnt/HC_Volume_11396573/lossless/push.rocks/smartnginx/nginxconfig/hosts/default.private.pem;
|
||||
rewrite ^ https://git.zone redirect;
|
||||
}
|
||||
|
||||
include /mnt/HC_Volume_11396573/lossless/push.rocks/smartnginx/nginxconfig/hosts/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
daemon off;
|
@ -1,29 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
72
package.json
72
package.json
@ -1,66 +1,40 @@
|
||||
{
|
||||
"name": "@push.rocks/smartnginx",
|
||||
"version": "2.0.52",
|
||||
"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",
|
||||
"name": "smartnginx",
|
||||
"version": "1.0.6",
|
||||
"description": "control nginx from node, TypeScript ready",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "tstest test/",
|
||||
"cleanTest": "(rm -r nginxconfig) && npm run test",
|
||||
"build": "(tsbuild --allowimplicitany)"
|
||||
"test": "(npmts)",
|
||||
"cleanTest": "(rm -r nginxconfig)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartnginx.git"
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartnginx.git"
|
||||
},
|
||||
"keywords": [
|
||||
"nginx",
|
||||
"node.js",
|
||||
"TypeScript",
|
||||
"configuration management",
|
||||
"web server",
|
||||
"reverse proxy",
|
||||
"SSL certificates"
|
||||
"nginx"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartnginx/issues"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/smartnginx",
|
||||
"homepage": "https://gitlab.com/pushrocks/smartnginx#README",
|
||||
"dependencies": {
|
||||
"@push.rocks/lik": "^6.0.2",
|
||||
"@push.rocks/smartfile": "^10.0.26",
|
||||
"@push.rocks/smartlog": "^3.0.2",
|
||||
"@push.rocks/smartpath": "^5.0.11",
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
"@push.rocks/smartshell": "^3.0.3",
|
||||
"@push.rocks/smartstring": "^4.0.7",
|
||||
"@push.rocks/smartunique": "^3.0.3",
|
||||
"selfsigned": "^2.1.1"
|
||||
"@types/q": "0.x.x",
|
||||
"@types/shelljs": "0.x.x",
|
||||
"beautylog": "^5.0.20",
|
||||
"cert": "^1.0.7",
|
||||
"q": "^1.4.1",
|
||||
"shelljs": "^0.7.3",
|
||||
"smartfile": "^4.0.13",
|
||||
"smartstring": "^2.0.15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.66",
|
||||
"@gitzone/tsrun": "^1.2.44",
|
||||
"@gitzone/tstest": "^1.0.77",
|
||||
"@push.rocks/qenv": "^5.0.2",
|
||||
"@push.rocks/tapbundle": "^5.0.8"
|
||||
},
|
||||
"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"
|
||||
]
|
||||
"npmts-g": "^5.2.8",
|
||||
"qenv": "^1.0.8",
|
||||
"should": "^10.0.0",
|
||||
"typings-test": "^1.0.1"
|
||||
}
|
||||
}
|
4819
pnpm-lock.yaml
generated
4819
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
|
93
readme.md
93
readme.md
@ -1,93 +0,0 @@
|
||||
# @push.rocks/smartnginx
|
||||
control nginx from node, TypeScript ready
|
||||
|
||||
## Install
|
||||
To install `@push.rocks/smartnginx`, you can use npm (Node Package Manager). Open your terminal and run:
|
||||
```bash
|
||||
npm install @push.rocks/smartnginx --save
|
||||
```
|
||||
This will download and install `@push.rocks/smartnginx` and its dependencies into your project's `node_modules` folder and save it as a dependency in your project's `package.json` file.
|
||||
|
||||
## Usage
|
||||
`@push.rocks/smartnginx` is a powerful library for interacting with Nginx programmatically using Node.js and TypeScript. It simplifies tasks such as configuring hosts, deploying configurations, and managing SSL certificates. Below is a comprehensive guide to using the library effectively in your TypeScript projects.
|
||||
|
||||
### Getting Started
|
||||
First, ensure you have imported the library into your TypeScript file. Use ESM syntax as shown:
|
||||
```typescript
|
||||
import { SmartNginx, NginxHost } from '@push.rocks/smartnginx';
|
||||
```
|
||||
|
||||
### Initialize SmartNginx
|
||||
Before you interact with Nginx, you need to create an instance of `SmartNginx`. This object acts as the main interface to your Nginx server. You can specify a default proxy URL that requests will be redirected to if no matching host is found.
|
||||
```typescript
|
||||
const smartNginx = new SmartNginx({
|
||||
defaultProxyUrl: 'https://your-default-url.com'
|
||||
});
|
||||
```
|
||||
|
||||
### Add Host Candidates
|
||||
To serve content or applications via Nginx, you will define hosts. Each host corresponds to a domain or subdomain and can be configured with specific rules. Here's how to add host candidates:
|
||||
```typescript
|
||||
const myHost = smartNginx.addHostCandidate({
|
||||
hostName: 'example.com',
|
||||
destination: 'localhost',
|
||||
destinationPort: 8080,
|
||||
privateKey: '<Your SSL Private Key>',
|
||||
publicKey: '<Your SSL Public Key>'
|
||||
});
|
||||
```
|
||||
Replace `'example.com'`, `'localhost'`, `8080`, `'<Your SSL Private Key>'`, and `'<Your SSL Public Key>'` with your actual host name, destination IP or hostname, port number, and SSL keys respectively.
|
||||
|
||||
### Deploying Configuration
|
||||
After adding all your host candidates, you will need to apply these configurations for Nginx to recognize and use them. Deploy the configuration as follows:
|
||||
```typescript
|
||||
await smartNginx.deploy();
|
||||
```
|
||||
This method checks for any changes in your host configurations compared to what's currently deployed and updates the Nginx configuration accordingly.
|
||||
|
||||
### Managing SSL Certificates
|
||||
When setting up SSL for your hosts, you will provide the paths to the private key and public certificate. It's essential to ensure these files are securely stored and accessible by the library during deployment.
|
||||
|
||||
### Handling Multiple Hosts
|
||||
You can add multiple host candidates using `addHostCandidate` method for different domains or subdomains, each with unique configurations. Here's an example of adding another host:
|
||||
```typescript
|
||||
const anotherHost = smartNginx.addHostCandidate({
|
||||
hostName: 'sub.example.com',
|
||||
destination: 'localhost',
|
||||
destinationPort: 9090,
|
||||
privateKey: '<Another SSL Private Key>',
|
||||
publicKey: '<Another SSL Public Key>'
|
||||
});
|
||||
```
|
||||
|
||||
### Reloading Configurations
|
||||
If at any time you make changes to your host configurations and need to apply these changes, simply call the `deploy` method again. `@push.rocks/smartnginx` efficiently detects changes and reloads Nginx with the new configurations.
|
||||
|
||||
### Stopping SmartNginx
|
||||
To stop the Nginx process managed by `@push.rocks/smartnginx`, use:
|
||||
```typescript
|
||||
await smartNginx.stop();
|
||||
```
|
||||
Bear in mind that this might affect your web services if they rely on the Nginx instance you are stopping.
|
||||
|
||||
### Conclusion
|
||||
`@push.rocks/smartnginx` abstracts away much of the complexity involved in managing Nginx configurations, offering a TypeScript-ready solution for Node.js projects. With simple method calls, you can automate and manage your Nginx server programmatically, making it an excellent tool for developers seeking to integrate Nginx management into their applications or deployment workflows.
|
||||
|
||||
## 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
Normal file
2
test/test.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import "typings-test";
|
||||
import "should";
|
61
test/test.js
Normal file
61
test/test.js
Normal file
@ -0,0 +1,61 @@
|
||||
"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.NginxHost({
|
||||
hostName: "test100.bleu.de",
|
||||
type: smartnginx.hostTypes.reverseProxy,
|
||||
destination: "192.192.192.191"
|
||||
});
|
||||
testNginxZone02 = new smartnginx.NginxHost({
|
||||
hostName: "test102.bleu.de",
|
||||
type: smartnginx.hostTypes.reverseProxy,
|
||||
destination: "192.192.192.192"
|
||||
});
|
||||
testNginxZone01.should.be.instanceof(smartnginx.NginxHost);
|
||||
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.addHost(testNginxZone01);
|
||||
testNginxConfig.addHost(testNginxZone02);
|
||||
});
|
||||
});
|
||||
describe(".deploy()", function () {
|
||||
this.timeout(600000);
|
||||
it("should deploy a config from an instance", function (done) {
|
||||
testNginxConfig.deploy()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe(".stop", function () {
|
||||
it("should end the process", function () {
|
||||
testNginxConfig.nginxProcess.stop();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxJQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDOUIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQix1QkFBbUIsTUFBTSxDQUFDLENBQUE7QUFDMUIsTUFBWSxVQUFVLFdBQU0sZUFBZSxDQUFDLENBQUE7QUFFNUMsb0JBQW9CO0FBQ3BCLElBQUksUUFBUSxHQUFHLElBQUksV0FBSSxDQUFDLE9BQU8sQ0FBQyxHQ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BQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFDLENBQUMifQ==
|
93
test/test.ts
93
test/test.ts
@ -1,55 +1,60 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import path = require('path');
|
||||
import "typings-test";
|
||||
import path = require("path");
|
||||
import "should";
|
||||
import {Qenv} from "qenv";
|
||||
import * as smartnginx from "../dist/index";
|
||||
|
||||
import { Qenv } from '@push.rocks/qenv';
|
||||
const testQenv = new Qenv('./', './.nogit/');
|
||||
|
||||
import * as smartnginx from '../ts/index.js';
|
||||
|
||||
let testSmartNginx: smartnginx.SmartNginx;
|
||||
// setup environment
|
||||
let testQenv = new Qenv(process.cwd(),path.join(process.cwd(),".nogit"));
|
||||
describe("smartnginx",function(){
|
||||
let testNginxConfig:smartnginx.NginxConfig;
|
||||
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);
|
||||
describe("NginxZone",function(){
|
||||
it(`"new NginxZone()" should produce an instance of NginxConfig`,function(){
|
||||
testNginxZone01 = new smartnginx.NginxHost({
|
||||
hostName:"test100.bleu.de",
|
||||
type:smartnginx.hostTypes.reverseProxy,
|
||||
destination:"192.192.192.191"
|
||||
});
|
||||
|
||||
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({
|
||||
hostName:"test102.bleu.de",
|
||||
type:smartnginx.hostTypes.reverseProxy,
|
||||
destination:"192.192.192.192"
|
||||
});
|
||||
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
|
||||
hostName: 'test102.bleu.de',
|
||||
destination: '192.192.192.192',
|
||||
destinationPort: 3050,
|
||||
privateKey: 'some private',
|
||||
publicKey: 'some public',
|
||||
testNginxZone01.should.be.instanceof(smartnginx.NginxHost);
|
||||
console.log(testNginxZone01.configString);
|
||||
});
|
||||
expect(testNginxZone01).toBeInstanceOf(smartnginx.NginxHost);
|
||||
});
|
||||
|
||||
tap.test('.addHostCandidate() should add a zone to NginxConfig Object', async () => {
|
||||
testSmartNginx.addHostCandidate(testNginxZone01);
|
||||
testSmartNginx.addHostCandidate(testNginxZone02);
|
||||
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
|
||||
});
|
||||
|
||||
tap.test('.deploy() should deploy a config from an instance', async () => {
|
||||
await testSmartNginx.deploy();
|
||||
testNginxConfig.should.be.instanceof(smartnginx.NginxConfig);
|
||||
});
|
||||
|
||||
tap.test('should not redeploy', async () => {
|
||||
testSmartNginx.addHostCandidate(testNginxZone01);
|
||||
testSmartNginx.addHostCandidate(testNginxZone02);
|
||||
await testSmartNginx.deploy();
|
||||
describe(".addZone()",function(){
|
||||
it("should add a zone to NginxConfig Object",function(){
|
||||
testNginxConfig.addHost(testNginxZone01);
|
||||
testNginxConfig.addHost(testNginxZone02);
|
||||
})
|
||||
});
|
||||
describe(".deploy()",function(){
|
||||
this.timeout(600000);
|
||||
it("should deploy a config from an instance",function(done){
|
||||
testNginxConfig.deploy()
|
||||
.then(() => {
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
describe(".stop",function(){
|
||||
it("should end the process",function(){
|
||||
testNginxConfig.nginxProcess.stop();
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
tap.test('.stop() should end the process', async () => {
|
||||
testSmartNginx.nginxProcess.stop();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,8 +0,0 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartnginx',
|
||||
version: '2.0.52',
|
||||
description: 'control nginx from node, TypeScript ready'
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
|
||||
// classes
|
||||
export * from './smartnginx.classes.smartnginx.js';
|
||||
export * from './smartnginx.classes.nginxprocess.js';
|
||||
export * from './smartnginx.classes.nginxhost.js';
|
||||
export * from "./smartnginx.classes.nginxconfig";
|
||||
export * from "./smartnginx.classes.nginxprocess";
|
||||
export * from "./smartnginx.classes.nginxhost";
|
@ -1,7 +0,0 @@
|
||||
export interface IHostConfig {
|
||||
hostName: string;
|
||||
destination: string;
|
||||
destinationPort: number;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
}
|
71
ts/smartnginx.classes.nginxconfig.ts
Normal file
71
ts/smartnginx.classes.nginxconfig.ts
Normal file
@ -0,0 +1,71 @@
|
||||
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";
|
||||
let allConfigs: NginxConfig[] = [];
|
||||
|
||||
/**
|
||||
* main class that manages a NginxInstance
|
||||
*/
|
||||
export class NginxConfig {
|
||||
hosts: NginxHost[] = [];
|
||||
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 Hosts
|
||||
addHost(nginxHostArg: NginxHost){
|
||||
this.hosts.push(nginxHostArg);
|
||||
}
|
||||
listHosts(): NginxHost[]{
|
||||
return this.hosts;
|
||||
};
|
||||
removeHost(nginxHostArg: NginxHost) {
|
||||
|
||||
}
|
||||
clean() {
|
||||
this.hosts = [];
|
||||
}
|
||||
// handle deployment of hosts
|
||||
deploy() {
|
||||
let done = plugins.q.defer();
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxHostFileBase);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
|
||||
for (let config of allConfigs) {
|
||||
config.isDeployed = false;
|
||||
};
|
||||
this.isDeployed = true;
|
||||
// write base config
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
snippets.getBaseConfigString(),
|
||||
paths.nginxConfFile
|
||||
);
|
||||
// deploy hosts
|
||||
let promiseArray = [];
|
||||
for (let host of this.hosts) {
|
||||
let hostDeployedPromise = host.deploy(this.cert);
|
||||
hostDeployedPromise.then(() => {
|
||||
plugins.beautylog.info(`Host ${host.hostName} deployed!`);
|
||||
this.nginxProcess.reloadConfig();
|
||||
});
|
||||
promiseArray.push(hostDeployedPromise);
|
||||
};
|
||||
plugins.q.all(promiseArray)
|
||||
.then(() => {
|
||||
done.resolve();
|
||||
});
|
||||
|
||||
return done.promise;
|
||||
};
|
||||
};
|
@ -1,62 +1,43 @@
|
||||
import * as plugins from './smartnginx.plugins.js';
|
||||
import * as paths from './smartnginx.paths.js';
|
||||
import * as snippets from './smartnginx.snippets.js';
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as paths from "./smartnginx.paths";
|
||||
import * as snippets from "./smartnginx.snippets"
|
||||
|
||||
import { SmartNginx } from './smartnginx.classes.smartnginx.js';
|
||||
|
||||
import { type IHostConfig } from './interfaces/hostconfig.js';
|
||||
/**
|
||||
* the host config data that NginxHost needs to create a valid instance
|
||||
*/
|
||||
export interface IHostConfigData {
|
||||
hostName: string,
|
||||
type: hostTypes,
|
||||
destination: string
|
||||
}
|
||||
|
||||
export enum hostTypes {
|
||||
reverseProxy,
|
||||
static
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
export class NginxHost {
|
||||
hostName: string; // the host name e.g. domain name
|
||||
type: hostTypes;
|
||||
destination: string;
|
||||
configString: string; // the actual host config file as string
|
||||
constructor(optionsArg:IHostConfigData) {
|
||||
this.hostName = optionsArg.hostName;
|
||||
this.type = optionsArg.type;
|
||||
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`);
|
||||
|
||||
this.configString = snippets.getHostConfigString(optionsArg.hostName, optionsArg.destination);
|
||||
};
|
||||
deploy(certInstanceArg: plugins.cert.Cert) {
|
||||
let done = plugins.q.defer();
|
||||
let filePath = plugins.path.join(paths.nginxHostFileBase, this.hostName + ".conf");
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
plugins.smartfile.memory.toFsSync(this.configString, filePath);
|
||||
// get cert
|
||||
certInstanceArg.getDomainCert(this.hostName)
|
||||
.then(done.resolve);
|
||||
return done.promise;
|
||||
};
|
||||
};
|
@ -1,67 +1,74 @@
|
||||
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';
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as paths from "./smartnginx.paths";
|
||||
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
|
||||
import { NginxHost } from "./smartnginx.classes.nginxhost";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
started: boolean = false;
|
||||
nginxConfig:NginxConfig;
|
||||
nginxChildProcess: plugins.childProcess.ChildProcess;
|
||||
constructor(nginxConfigArg) {
|
||||
this.nginxConfig = nginxConfigArg;
|
||||
};
|
||||
|
||||
/**
|
||||
* start nginx
|
||||
*/
|
||||
public async start() {
|
||||
if (!this.nginxChildProcess) {
|
||||
this.nginxChildProcess = (
|
||||
await this.smartshellInstance.execStreaming(`nginx -c ${paths.nginxConfFile}`)
|
||||
).childProcess;
|
||||
}
|
||||
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;
|
||||
console.log('info', 'started Nginx!');
|
||||
}
|
||||
plugins.beautylog.info("started Nginx!");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* reload config
|
||||
*/
|
||||
public async reloadConfig() {
|
||||
if (!this.started) {
|
||||
reloadConfig(){
|
||||
let done = plugins.q.defer();
|
||||
if(this.started == false){
|
||||
this.start();
|
||||
} else {
|
||||
await this.smartshellInstance.exec('nginx -s reload');
|
||||
}
|
||||
this.smartNginxRef.logger.log('info', 'NginxProcess has loaded the new config!');
|
||||
}
|
||||
plugins.shelljs.exec("nginx -s reload");
|
||||
};
|
||||
plugins.beautylog.ok("NginxProcess has loaded the new config!")
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* stop the nginx instance
|
||||
*/
|
||||
public async stop() {
|
||||
if (this.nginxChildProcess) {
|
||||
this.smartshellInstance.exec('nginx -s quit');
|
||||
stop() {
|
||||
let done = plugins.q.defer();
|
||||
if (typeof this.nginxChildProcess != "undefined") {
|
||||
plugins.shelljs.exec("nginx -s quit");
|
||||
this.started = false;
|
||||
this.smartNginxRef.logger.log('info', 'stopped Nginx!');
|
||||
plugins.beautylog.info("stopped Nginx!");
|
||||
} else {
|
||||
this.smartNginxRef.logger.log('info', 'nginx already stopped!');
|
||||
}
|
||||
}
|
||||
plugins.beautylog.log("nginx already stopped!");
|
||||
};
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* checks if nginx is in path
|
||||
*/
|
||||
public check(): boolean {
|
||||
check(): boolean {
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,160 +0,0 @@
|
||||
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
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import * as plugins from './smartnginx.plugins.js';
|
||||
import * as plugins from "./smartnginx.plugins"
|
||||
|
||||
// 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');
|
||||
export let packageBase = plugins.path.join(__dirname,"../");
|
||||
export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig");
|
||||
export let nginxHostFileBase = plugins.path.join(nginxConfigBase,"hosts");
|
||||
export let nginxCertBase = plugins.path.join(nginxConfigBase,"cert");
|
||||
|
||||
// files
|
||||
export const nginxConfFile = plugins.path.join(nginxConfigDirPath, 'nginx.conf');
|
||||
export let nginxConfFile = plugins.path.join(nginxConfigBase,"nginx.conf");
|
@ -1,21 +1,9 @@
|
||||
// native
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
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, smartfile, smartlog, smartpath, smartpromise, smartshell, smartstring, smartunique };
|
||||
|
||||
// thirdparty scope
|
||||
import * as selfsigned from 'selfsigned';
|
||||
|
||||
export { selfsigned };
|
||||
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");
|
@ -1,10 +1,10 @@
|
||||
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(`
|
||||
import * as plugins from "./smartnginx.plugins";
|
||||
import * as paths from "./smartnginx.paths";
|
||||
export let getBaseConfigString = () => {
|
||||
let baseConfig = plugins.smartstring.indent.normalize(`
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
pid /run/nginx/nginx.pid;
|
||||
pid /run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
@ -63,43 +63,22 @@ export let getBaseConfigString = (defaultProxy: string) => {
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
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 ${paths.nginxHostFileBase}/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
daemon off;
|
||||
`);
|
||||
return baseConfig;
|
||||
};
|
||||
}
|
||||
|
||||
export let getHostConfigString = (
|
||||
hostNameArg: string,
|
||||
destinationIpArg: string,
|
||||
destinationPortArg = 80
|
||||
) => {
|
||||
const hostConfig = plugins.smartstring.indent.normalize(`
|
||||
|
||||
export let getHostConfigString = (hostNameArg:string,destinationIpArg:string) => {
|
||||
let hostConfig = plugins.smartstring.indent.normalize(`
|
||||
upstream ${hostNameArg} {
|
||||
keepalive 100;
|
||||
server ${destinationIpArg}:${destinationPortArg};
|
||||
server ${destinationIpArg};
|
||||
}
|
||||
|
||||
server {
|
||||
# The keepalive parameter sets the maximum number of idle keepalive connections
|
||||
# to upstream servers that are preserved in the cache of each worker process. When
|
||||
# this number is exceeded, the least recently used connections are closed.
|
||||
listen *:80 ;
|
||||
server_name ${hostNameArg};
|
||||
rewrite ^ https://${hostNameArg}$request_uri? permanent;
|
||||
@ -108,20 +87,18 @@ export let getHostConfigString = (
|
||||
server {
|
||||
listen *:443 ssl;
|
||||
server_name ${hostNameArg};
|
||||
ssl_certificate ${paths.nginxHostDirPath}/${hostNameArg}.public.pem;
|
||||
ssl_certificate_key ${paths.nginxHostDirPath}/${hostNameArg}.private.pem;
|
||||
ssl_certificate ${paths.nginxCertBase}/${hostNameArg}/fullchain.pem;
|
||||
ssl_certificate_key ${paths.nginxCertBase}/${hostNameArg}/privkey.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://${hostNameArg};
|
||||
include /etc/nginx/proxy_params;
|
||||
}
|
||||
location ~ /\.git {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
`);
|
||||
return hostConfig;
|
||||
};
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user