Compare commits

...

10 Commits

31 changed files with 9074 additions and 2141 deletions

View 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

View 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

4
.gitignore vendored
View File

@@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@@ -1,119 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
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
script:
- npmci node install lts
- npmci npm publish
only:
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:18-dind
stage: metadata
script:
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View 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
View 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"]
}
}
}
}
}
}
]
}

View File

@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Lossless GmbH Copyright (c) 2016 Task Venture Capital GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,40 +0,0 @@
# @pushrocks/smartnginx
control nginx from node, TypeScript ready
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartnginx)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartnginx)
* [github.com (source mirror)](https://github.com/pushrocks/smartnginx)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnginx/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartnginx/badges/master/build.svg)](https://gitlab.com/pushrocks/smartnginx/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartnginx/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartnginx/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartnginx.svg)](https://www.npmjs.com/package/@pushrocks/smartnginx)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartnginx/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartnginx)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage
We recommend the use of TypeScript! :)
```typescript
import * as smartnginx from 'smartnginx';
const smartnginxInstance = new smartnginx.SmartNginx();
myNginxHost = new smartnginx.NginxHost({
hostName: 'some.example.com',
type: 'reverseProxy',
destination: '192.192.192.192' // some destination IP
});
myNginxConfig.addZone(myNginxZone); // adds the zone to the config
myNginxConfig.deploy(); // deploys the referenced NginxConfig and gracefully reloads it
```
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

59
changelog.md Normal file
View 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).

View File

@@ -1,15 +1,27 @@
-----BEGIN RSA PRIVATE KEY----- -----BEGIN RSA PRIVATE KEY-----
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
-----END RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----

View File

@@ -1,13 +1,19 @@
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIIB/zCCAWigAwIBAgIJeD6pc7FCt9rnMA0GCSqGSIb3DQEBBQUAMB4xHDAaBgNV MIIDBDCCAeygAwIBAgIJZid+XT7/NTaWMA0GCSqGSIb3DQEBBQUAMB4xHDAaBgNV
BAMTE3NlbGZzaWduZWQuZ2l0LnpvbmUwHhcNMTkwODIwMjAzMDI1WhcNMjAwODE5 BAMTE3NlbGZzaWduZWQuZ2l0LnpvbmUwHhcNMjUxMTI3MTMxMzM0WhcNMjYxMTI3
MjAzMDI1WjAeMRwwGgYDVQQDExNzZWxmc2lnbmVkLmdpdC56b25lMIGfMA0GCSqG MTMxMzM0WjAeMRwwGgYDVQQDExNzZWxmc2lnbmVkLmdpdC56b25lMIIBIjANBgkq
SIb3DQEBAQUAA4GNADCBiQKBgQCMGIi2uxtbfbDIiyL6SWwZb1RdSpjGFHwzlR+m hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuO16Nu4tMkmBqsNWezt3ENqnsbWNUqC+
ipbwgW1JsYldFs463PvxsMFgyQ6Nzndj3IE1mpYQgWYSS69mV8B3XxusrxnOGeO0 curHyXURaoIH2wQ16DIZaBIbO/WndNisMy6TnxJtiMVbKGKjkRH4w3qegthIRCKL
0IdA+qPGakzqSm+/2ualnz6nDeVWTvQuM15Ki6WQsbvmcIKngs+5tsmYfTiAnpFU D3+Yl1ffqpHRz19hkNxVg4HfXRQMfH0Pnvd/4wB7g2mapk8SMwsTuEZ0j/7dAwc0
v3t6zQIDAQABo0UwQzAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIC9DAmBgNVHREE dqw94g+aehgZlvxUDFQjI/4kU9EiheDZ9TPREBMfeIb82zapINekKq5TkN/euWfs
HzAdhhtodHRwOi8vZXhhbXBsZS5vcmcvd2ViaWQjbWUwDQYJKoZIhvcNAQEFBQAD fpbZZ6qWZvTX8NegulKOtDCCFauXKv2LNqy4jxWQef2XfMT8Jr4Txud3F8zqfexJ
gYEARLQhxnvrKNGs758MzDTbf3lBuMd5jf42YFcUdEPI6jg9knKwqcgd5eNkZtNM Yq5ywjH07ecsyi7a/ifv7VLNXUEgwI6OFJHYnFZ314S6KlurocQUWQIDAQABo0Uw
DFPOFJf3HIJOLeOhXZ4bzQpcxVkkDAMUloKmQNypZlRWzkZt0jLgG0/ofKvvqX7c QzAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIC9DAmBgNVHREEHzAdhhtodHRwOi8v
DpzwgTIoJwWlpbug788LEm3HcTVPu0LxQ1lOpgt0PWPnasc= ZXhhbXBsZS5vcmcvd2ViaWQjbWUwDQYJKoZIhvcNAQEFBQADggEBAH3qUHaBnNn+
e1qlZ0gUooJlLXU5tLGR9cVFV1dKuE5yxZhT0qal4A6Vif1mGKYXmHC4q0/atNsQ
RBvrbpoVtJxWpb6iIh1L5WWeP5OxqeLwZ8gp2Qj67CkwmccjIS66kkpwHBkBmXU9
nRlmGOj9OBHczqE0cp4dW6pCVvRtzC+wTX9oqAdmjyD8S8oo8I2fjCL4pJTPQtbV
RlaryWxlxscXYArA7iE9A5Cl5DdJtkOKS48Rbfw3BEQpgL0J4VeF8Lbb+ryk6BbG
XXkkH570cIdTs588gdfhkS8T6NIl+1Aicqmf+v6j3MHrzyLK3SZTQ83hoCRAEMfW
SPkrHSeL6h8=
-----END CERTIFICATE----- -----END CERTIFICATE-----

View File

@@ -15,8 +15,8 @@ server {
server { server {
listen *:443 ssl; listen *:443 ssl;
server_name test100.bleu.de; server_name test100.bleu.de;
ssl_certificate /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/test100.bleu.de.public.pem; ssl_certificate /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/test100.bleu.de.public.pem;
ssl_certificate_key /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/test100.bleu.de.private.pem; ssl_certificate_key /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/test100.bleu.de.private.pem;
location / { location / {
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_buffering off; proxy_buffering off;

View File

@@ -15,8 +15,8 @@ server {
server { server {
listen *:443 ssl; listen *:443 ssl;
server_name test102.bleu.de; server_name test102.bleu.de;
ssl_certificate /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/test102.bleu.de.public.pem; ssl_certificate /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/test102.bleu.de.public.pem;
ssl_certificate_key /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/test102.bleu.de.private.pem; ssl_certificate_key /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/test102.bleu.de.private.pem;
location / { location / {
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_buffering off; proxy_buffering off;

View File

@@ -68,12 +68,12 @@ http {
server { server {
listen *:443 ssl default_server; listen *:443 ssl default_server;
server_name selfsigned.git.zone; server_name selfsigned.git.zone;
ssl_certificate /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/default.public.pem; ssl_certificate /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/default.public.pem;
ssl_certificate_key /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/default.private.pem; ssl_certificate_key /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/default.private.pem;
rewrite ^ https://git.zone redirect; rewrite ^ https://git.zone redirect;
} }
include /Users/philkunz/gitlab/pushrocks_meta/smartnginx/nginxconfig/hosts/*.conf; include /mnt/data/lossless/push.rocks/smartnginx/nginxconfig/hosts/*.conf;
include /etc/nginx/sites-enabled/*; include /etc/nginx/sites-enabled/*;
} }
daemon off; daemon off;

View File

@@ -4,13 +4,26 @@
}, },
"npmdocker": {}, "npmdocker": {},
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "code.foss.global",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "smartnginx", "gitrepo": "smartnginx",
"shortDescription": "control nginx from node, TypeScript ready", "description": "A TypeScript library for controlling Nginx from Node.js, with support for generating and managing Nginx configurations dynamically.",
"npmPackagename": "@pushrocks/smartnginx", "npmPackagename": "@push.rocks/smartnginx",
"license": "MIT" "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"
} }
} }

1819
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,56 +1,65 @@
{ {
"name": "@pushrocks/smartnginx", "name": "@push.rocks/smartnginx",
"version": "2.0.51", "version": "2.0.53",
"private": false, "private": false,
"description": "control nginx from node, TypeScript ready", "description": "A TypeScript library for controlling Nginx from Node.js, with support for generating and managing Nginx configurations dynamically.",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "tstest test/", "test": "tstest test/ --verbose",
"cleanTest": "(rm -r nginxconfig) && npm run test", "cleanTest": "(rm -r nginxconfig) && npm run test",
"build": "(tsbuild)" "build": "(tsbuild tsfolders --allowimplicitany)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/smartnginx.git" "url": "https://code.foss.global/push.rocks/smartnginx.git"
}, },
"keywords": [ "keywords": [
"nginx" "nginx",
"node.js",
"TypeScript",
"configuration management",
"web server",
"reverse proxy",
"SSL certificates"
], ],
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://gitlab.com/pushrocks/smartnginx/issues" "url": "https://gitlab.com/pushrocks/smartnginx/issues"
}, },
"homepage": "https://gitlab.com/pushrocks/smartnginx#README", "homepage": "https://code.foss.global/push.rocks/smartnginx",
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.10", "@push.rocks/lik": "^6.2.2",
"@pushrocks/smartfile": "^7.0.4", "@push.rocks/smartfs": "^1.1.0",
"@pushrocks/smartlog": "^2.0.19", "@push.rocks/smartlog": "^3.1.10",
"@pushrocks/smartpromise": "^3.0.2", "@push.rocks/smartpath": "^6.0.0",
"@pushrocks/smartshell": "^2.0.23", "@push.rocks/smartpromise": "^4.2.3",
"@pushrocks/smartstring": "^3.0.10", "@push.rocks/smartshell": "^3.3.0",
"@pushrocks/smartunique": "^3.0.1", "@push.rocks/smartstring": "^4.1.0",
"selfsigned": "^1.10.4" "@push.rocks/smartunique": "^3.0.9",
"selfsigned": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.11", "@git.zone/tsbuild": "^3.1.0",
"@gitzone/tsrun": "^1.2.8", "@git.zone/tsrun": "^2.0.0",
"@gitzone/tstest": "^1.0.24", "@git.zone/tstest": "^3.1.3",
"@pushrocks/qenv": "^4.0.2", "@push.rocks/qenv": "^6.1.3"
"@pushrocks/tapbundle": "^3.0.11",
"tslint": "^5.19.0",
"tslint-config-prettier": "^1.18.0"
}, },
"files": [ "files": [
"ts/*", "ts/**/*",
"ts_web/*", "ts_web/**/*",
"dist/*", "dist/**/*",
"dist_web/*", "dist_*/**/*",
"dist_ts_web/*", "dist_ts/**/*",
"assets/*", "dist_ts_web/**/*",
"assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"type": "module",
"browserslist": [
"last 1 chrome versions"
] ]
} }

8315
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@@ -0,0 +1 @@

267
readme.md Normal file
View 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.

View File

@@ -1,10 +1,9 @@
import { tap, expect } from '@pushrocks/tapbundle'; import { tap, expect } from '@git.zone/tstest/tapbundle';
import path = require('path'); import * as path from 'node:path';
import { Qenv } from '@pushrocks/qenv'; import { Qenv } from '@push.rocks/qenv';
const testQenv = new Qenv('./', './.nogit/');
import * as smartnginx from '../ts/index'; import * as smartnginx from '../ts/index.js';
let testSmartNginx: smartnginx.SmartNginx; let testSmartNginx: smartnginx.SmartNginx;
let testNginxZone01: smartnginx.NginxHost; let testNginxZone01: smartnginx.NginxHost;
@@ -12,7 +11,7 @@ let testNginxZone02: smartnginx.NginxHost;
tap.test('should create a valid instance of SmartNginx', async () => { tap.test('should create a valid instance of SmartNginx', async () => {
testSmartNginx = new smartnginx.SmartNginx({ defaultProxyUrl: 'https://git.zone' }); testSmartNginx = new smartnginx.SmartNginx({ defaultProxyUrl: 'https://git.zone' });
expect(testSmartNginx).to.be.instanceof(smartnginx.SmartNginx); expect(testSmartNginx).toBeInstanceOf(smartnginx.SmartNginx);
}); });
tap.test(`should produce an instance of NginxConfig`, async () => { tap.test(`should produce an instance of NginxConfig`, async () => {
@@ -21,16 +20,16 @@ tap.test(`should produce an instance of NginxConfig`, async () => {
destination: '192.192.192.191', destination: '192.192.192.191',
destinationPort: 3000, destinationPort: 3000,
privateKey: 'some private', privateKey: 'some private',
publicKey: 'some public' publicKey: 'some public',
}); });
testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, { testNginxZone02 = new smartnginx.NginxHost(testSmartNginx, {
hostName: 'test102.bleu.de', hostName: 'test102.bleu.de',
destination: '192.192.192.192', destination: '192.192.192.192',
destinationPort: 3050, destinationPort: 3050,
privateKey: 'some private', privateKey: 'some private',
publicKey: 'some public' publicKey: 'some public',
}); });
expect(testNginxZone01).to.be.instanceof(smartnginx.NginxHost); expect(testNginxZone01).toBeInstanceOf(smartnginx.NginxHost);
}); });
tap.test('.addHostCandidate() should add a zone to NginxConfig Object', async () => { tap.test('.addHostCandidate() should add a zone to NginxConfig Object', async () => {
@@ -52,4 +51,4 @@ tap.test('.stop() should end the process', async () => {
testSmartNginx.nginxProcess.stop(); testSmartNginx.nginxProcess.stop();
}); });
tap.start(); export default tap.start();

8
ts/00_commitinfo_data.ts Normal file
View 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.'
}

View File

@@ -1,6 +1,4 @@
import * as plugins from './smartnginx.plugins';
// classes // classes
export * from './smartnginx.classes.smartnginx'; export * from './smartnginx.classes.smartnginx.js';
export * from './smartnginx.classes.nginxprocess'; export * from './smartnginx.classes.nginxprocess.js';
export * from './smartnginx.classes.nginxhost'; export * from './smartnginx.classes.nginxhost.js';

View File

@@ -1,13 +1,13 @@
import * as plugins from './smartnginx.plugins'; import * as plugins from './smartnginx.plugins.js';
import * as paths from './smartnginx.paths'; import * as paths from './smartnginx.paths.js';
import * as snippets from './smartnginx.snippets'; import * as snippets from './smartnginx.snippets.js';
import { SmartNginx } from './smartnginx.classes.smartnginx'; import { SmartNginx } from './smartnginx.classes.smartnginx.js';
import { IHostConfig } from './interfaces/hostconfig'; import { type IHostConfig } from './interfaces/hostconfig.js';
export enum hostTypes { export enum hostTypes {
reverseProxy reverseProxy,
} }
/** /**
@@ -53,10 +53,10 @@ export class NginxHost implements IHostConfig {
this.destination, this.destination,
this.destinationPort this.destinationPort
); );
plugins.smartfile.memory.toFsSync(this.configString, filePathConfig); await plugins.fs.file(filePathConfig).write(this.configString);
// write ssl // write ssl
plugins.smartfile.memory.toFsSync(this.privateKey, filePathPrivate); await plugins.fs.file(filePathPrivate).write(this.privateKey);
plugins.smartfile.memory.toFsSync(this.publicKey, filePathPublic); await plugins.fs.file(filePathPublic).write(this.publicKey);
} }
} }

View File

@@ -1,9 +1,7 @@
import * as plugins from './smartnginx.plugins'; import * as plugins from './smartnginx.plugins.js';
import * as paths from './smartnginx.paths'; import * as paths from './smartnginx.paths.js';
import { SmartNginx } from './smartnginx.classes.smartnginx'; import { SmartNginx } from './smartnginx.classes.smartnginx.js';
import { NginxHost } from './smartnginx.classes.nginxhost'; import { NginxHost } from './smartnginx.classes.nginxhost.js';
import { Smartshell } from '@pushrocks/smartshell';
import { ChildProcess } from 'child_process'; import { ChildProcess } from 'child_process';
@@ -14,8 +12,8 @@ export class NginxProcess {
public started: boolean = false; public started: boolean = false;
public smartNginxRef: SmartNginx; public smartNginxRef: SmartNginx;
private nginxChildProcess: ChildProcess; private nginxChildProcess: ChildProcess;
private smartshellInstance = new Smartshell({ private smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash' executor: 'bash',
}); });
constructor(nginxRefArg: SmartNginx) { constructor(nginxRefArg: SmartNginx) {
@@ -27,12 +25,12 @@ export class NginxProcess {
*/ */
public async start() { public async start() {
if (!this.nginxChildProcess) { if (!this.nginxChildProcess) {
this.nginxChildProcess = (await this.smartshellInstance.execStreaming( this.nginxChildProcess = (
`nginx -c ${paths.nginxConfFile}` await this.smartshellInstance.execStreaming(`nginx -c ${paths.nginxConfFile}`)
)).childProcess; ).childProcess;
} }
this.started = true; this.started = true;
plugins.smartlog.defaultLogger.log('info', 'started Nginx!'); console.log('info', 'started Nginx!');
} }
/** /**

View File

@@ -1,9 +1,9 @@
import * as plugins from './smartnginx.plugins'; import * as plugins from './smartnginx.plugins.js';
import * as paths from './smartnginx.paths'; import * as paths from './smartnginx.paths.js';
import * as snippets from './smartnginx.snippets'; import * as snippets from './smartnginx.snippets.js';
import { NginxHost } from './smartnginx.classes.nginxhost'; import { NginxHost } from './smartnginx.classes.nginxhost.js';
import { NginxProcess } from './smartnginx.classes.nginxprocess'; import { NginxProcess } from './smartnginx.classes.nginxprocess.js';
import { IHostConfig } from './interfaces/hostconfig'; import { type IHostConfig } from './interfaces/hostconfig.js';
export interface ISmartNginxContructorOptions { export interface ISmartNginxContructorOptions {
logger?: plugins.smartlog.Smartlog; logger?: plugins.smartlog.Smartlog;
@@ -18,15 +18,17 @@ export class SmartNginx {
public logger: plugins.smartlog.Smartlog; public logger: plugins.smartlog.Smartlog;
// the objectmaps // the objectmaps
private deployedHosts = new plugins.lik.Objectmap<NginxHost>(); private deployedHosts = new plugins.lik.ObjectMap<NginxHost>();
private hostCandidates = new plugins.lik.Objectmap<NginxHost>(); private hostCandidates = new plugins.lik.ObjectMap<NginxHost>();
public nginxProcess: NginxProcess = new NginxProcess(this); public nginxProcess: NginxProcess = new NginxProcess(this);
constructor(optionsArg: ISmartNginxContructorOptions) { constructor(optionsArg: ISmartNginxContructorOptions) {
this.options = optionsArg; this.options = optionsArg;
this.options.logger this.options.logger
? (this.logger = this.options.logger) ? (this.logger = this.options.logger)
: (this.logger = plugins.smartlog.defaultLogger); : (this.logger = new plugins.smartlog.Smartlog({
logContext: null
}));
} }
// =================== // ===================
@@ -48,7 +50,7 @@ export class SmartNginx {
* @param hostNameArg * @param hostNameArg
*/ */
public getDeployedNginxHostByHostName(hostNameArg: string): NginxHost { public getDeployedNginxHostByHostName(hostNameArg: string): NginxHost {
return this.deployedHosts.find(nginxHost => { return this.deployedHosts.findSync((nginxHost) => {
return nginxHost.hostName === hostNameArg; return nginxHost.hostName === hostNameArg;
}); });
} }
@@ -65,7 +67,7 @@ export class SmartNginx {
*/ */
public async removeDeployedHost(nginxHostArg: NginxHost) { public async removeDeployedHost(nginxHostArg: NginxHost) {
if (this.hostCandidates.isEmpty()) { if (this.hostCandidates.isEmpty()) {
this.deployedHosts.forEach(hostArg => { this.deployedHosts.forEach((hostArg) => {
this.hostCandidates.add(hostArg); this.hostCandidates.add(hostArg);
}); });
} }
@@ -80,9 +82,9 @@ export class SmartNginx {
private async areHostsDiverged(): Promise<boolean> { private async areHostsDiverged(): Promise<boolean> {
let hostCounter = 0; let hostCounter = 0;
let unfoundHosts = 0; let unfoundHosts = 0;
await this.hostCandidates.forEach(async hostCandidateArg => { await this.hostCandidates.forEach(async (hostCandidateArg) => {
let foundHost = false; let foundHost = false;
await this.deployedHosts.forEach(async deployedHostArg => { await this.deployedHosts.forEach(async (deployedHostArg) => {
if ( if (
hostCandidateArg.hostName === deployedHostArg.hostName && hostCandidateArg.hostName === deployedHostArg.hostName &&
hostCandidateArg.destination === deployedHostArg.destination && hostCandidateArg.destination === deployedHostArg.destination &&
@@ -114,10 +116,9 @@ export class SmartNginx {
this.hostCandidates.wipe(); this.hostCandidates.wipe();
// write base config // write base config
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigDirPath); await plugins.fs.directory(paths.nginxConfigDirPath).recursive().create();
plugins.smartfile.memory.toFsSync( await plugins.fs.file(paths.nginxConfFile).write(
snippets.getBaseConfigString(this.options.defaultProxyUrl), snippets.getBaseConfigString(this.options.defaultProxyUrl)
paths.nginxConfFile
); );
// write standard self signed certificate // write standard self signed certificate
@@ -127,15 +128,13 @@ export class SmartNginx {
); );
// deploy hosts // deploy hosts
plugins.smartfile.fs.ensureDirSync(paths.nginxHostDirPath); await plugins.fs.directory(paths.nginxHostDirPath).recursive().create();
plugins.smartfile.memory.toFsSync( await plugins.fs.file(
selfsignedCert.private,
plugins.path.join(paths.nginxHostDirPath, './default.private.pem') plugins.path.join(paths.nginxHostDirPath, './default.private.pem')
); ).write(selfsignedCert.private);
plugins.smartfile.memory.toFsSync( await plugins.fs.file(
selfsignedCert.cert,
plugins.path.join(paths.nginxHostDirPath, './default.public.pem') plugins.path.join(paths.nginxHostDirPath, './default.public.pem')
); ).write(selfsignedCert.cert);
for (const host of this.deployedHosts.getArray()) { for (const host of this.deployedHosts.getArray()) {
await host.deploy(); await host.deploy();
this.logger.log('info', `Host ${host.hostName} deployed!`); this.logger.log('info', `Host ${host.hostName} deployed!`);

View File

@@ -1,7 +1,7 @@
import * as plugins from './smartnginx.plugins'; import * as plugins from './smartnginx.plugins.js';
// directories // directories
export const packageBase = plugins.path.join(__dirname, '../'); export const packageBase = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
export const nginxConfigDirPath = plugins.path.join(packageBase, 'nginxconfig'); export const nginxConfigDirPath = plugins.path.join(packageBase, 'nginxconfig');
export const nginxHostDirPath = plugins.path.join(nginxConfigDirPath, 'hosts'); export const nginxHostDirPath = plugins.path.join(nginxConfigDirPath, 'hosts');

View File

@@ -1,18 +1,23 @@
// native // native
import * as path from 'path'; import * as path from 'node:path';
export { path }; export { path };
// @pushrocks scope // @push.rocks scope
import * as lik from '@pushrocks/lik'; import * as lik from '@push.rocks/lik';
import * as smartlog from '@pushrocks/smartlog'; import * as smartfs from '@push.rocks/smartfs';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartlog from '@push.rocks/smartlog';
import * as smartshell from '@pushrocks/smartshell'; import * as smartpath from '@push.rocks/smartpath';
import * as smartfile from '@pushrocks/smartfile'; import * as smartpromise from '@push.rocks/smartpromise';
import * as smartstring from '@pushrocks/smartstring'; import * as smartshell from '@push.rocks/smartshell';
import * as smartunique from '@pushrocks/smartunique'; import * as smartstring from '@push.rocks/smartstring';
import * as smartunique from '@push.rocks/smartunique';
export { lik, smartlog, smartpromise, smartshell, smartfile, smartstring, 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 // thirdparty scope
import * as selfsigned from 'selfsigned'; import * as selfsigned from 'selfsigned';

View File

@@ -1,5 +1,5 @@
import * as plugins from './smartnginx.plugins'; import * as plugins from './smartnginx.plugins.js';
import * as paths from './smartnginx.paths'; import * as paths from './smartnginx.paths.js';
export let getBaseConfigString = (defaultProxy: string) => { export let getBaseConfigString = (defaultProxy: string) => {
const baseConfig = plugins.smartstring.indent.normalize(` const baseConfig = plugins.smartstring.indent.normalize(`
user www-data; user www-data;

14
tsconfig.json Normal file
View File

@@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

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