Compare commits

...

7 Commits

19 changed files with 7845 additions and 4103 deletions

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

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

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-----
MIICXQIBAAKBgQD5b6wtr4xHY5gxH0SR+V9XIQPH6DGe2PXlKWN02dgvg7Ej/4uA MIIEowIBAAKCAQEAuO16Nu4tMkmBqsNWezt3ENqnsbWNUqC+curHyXURaoIH2wQ1
7MmOnem2SUpWE2GwuKCAUCeZkj+riEmky0EWFexaM3BmcvWLSHZ6MAYg5FxTsUG8 6DIZaBIbO/WndNisMy6TnxJtiMVbKGKjkRH4w3qegthIRCKLD3+Yl1ffqpHRz19h
IXxNYUdTPpUBxaCX/yp/dvpiDqSMH67y9LwI85oWHx/zk1jMixaZXvOCXwIDAQAB kNxVg4HfXRQMfH0Pnvd/4wB7g2mapk8SMwsTuEZ0j/7dAwc0dqw94g+aehgZlvxU
AoGBALFXn1/f9uluuu753yO12/4zf9+qi1T3xmQGuCqFE7o8dD422vVv5KHcTiUH DFQjI/4kU9EiheDZ9TPREBMfeIb82zapINekKq5TkN/euWfsfpbZZ6qWZvTX8Neg
GK34G7Wsnph75JvAKjqHrGxZAk0NN59VK4Sl141S7qzXgjQf5Ks7r5y8v8AQgvEM ulKOtDCCFauXKv2LNqy4jxWQef2XfMT8Jr4Txud3F8zqfexJYq5ywjH07ecsyi7a
zOwutOqlGNHJZ1NlCDJuMNxUe/vyRXRl1WDCeJF6pt8huZgRAkEA/Ppqz8NyU+B7 /ifv7VLNXUEgwI6OFJHYnFZ314S6KlurocQUWQIDAQABAoIBAAIMpnWrBrSa+d5X
kaz3e39uCELsyaDl3Xf82JMmJASBlndso3l3H2ihihAMYHaH21IxKQnfaiKMyfK4 whB9uX27XITnXKpoAguNfHivvONBrcXGWVl+zkKh3ip4RFIfE7IjXpyQ6vEalD5j
tvONLB/eZwJBAPxqbKEzLqYM7ds8QG2fty7he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QpgL0J4VeF8Lbb+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 /mnt/HC_Volume_11396573/lossless/push.rocks/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 /mnt/HC_Volume_11396573/lossless/push.rocks/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 /mnt/HC_Volume_11396573/lossless/push.rocks/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 /mnt/HC_Volume_11396573/lossless/push.rocks/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 /mnt/HC_Volume_11396573/lossless/push.rocks/smartnginx/nginxconfig/hosts/default.public.pem; ssl_certificate /mnt/data/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; 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 /mnt/HC_Volume_11396573/lossless/push.rocks/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

@@ -6,12 +6,24 @@
"gitzone": { "gitzone": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "code.foss.global",
"gitscope": "push.rocks", "gitscope": "push.rocks",
"gitrepo": "smartnginx", "gitrepo": "smartnginx",
"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.",
"npmPackagename": "@push.rocks/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"
} }
} }

View File

@@ -1,45 +1,50 @@
{ {
"name": "@push.rocks/smartnginx", "name": "@push.rocks/smartnginx",
"version": "2.0.52", "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_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/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 --allowimplicitany)" "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": {
"@push.rocks/lik": "^6.0.2", "@push.rocks/lik": "^6.2.2",
"@push.rocks/smartfile": "^10.0.26", "@push.rocks/smartfs": "^1.1.0",
"@push.rocks/smartlog": "^3.0.2", "@push.rocks/smartlog": "^3.1.10",
"@push.rocks/smartpath": "^5.0.11", "@push.rocks/smartpath": "^6.0.0",
"@push.rocks/smartpromise": "^4.0.2", "@push.rocks/smartpromise": "^4.2.3",
"@push.rocks/smartshell": "^3.0.3", "@push.rocks/smartshell": "^3.3.0",
"@push.rocks/smartstring": "^4.0.7", "@push.rocks/smartstring": "^4.1.0",
"@push.rocks/smartunique": "^3.0.3", "@push.rocks/smartunique": "^3.0.9",
"selfsigned": "^2.1.1" "selfsigned": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.66", "@git.zone/tsbuild": "^3.1.0",
"@gitzone/tsrun": "^1.2.44", "@git.zone/tsrun": "^2.0.0",
"@gitzone/tstest": "^1.0.77", "@git.zone/tstest": "^3.1.3",
"@push.rocks/qenv": "^5.0.2", "@push.rocks/qenv": "^6.1.3"
"@push.rocks/tapbundle": "^5.0.8"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

11280
pnpm-lock.yaml generated

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,8 +1,7 @@
import { tap, expect } from '@push.rocks/tapbundle'; import { tap, expect } from '@git.zone/tstest/tapbundle';
import path = require('path'); import * as path from 'node:path';
import { Qenv } from '@push.rocks/qenv'; import { Qenv } from '@push.rocks/qenv';
const testQenv = new Qenv('./', './.nogit/');
import * as smartnginx from '../ts/index.js'; import * as smartnginx from '../ts/index.js';
@@ -52,4 +51,4 @@ tap.test('.stop() should end the process', async () => {
testSmartNginx.nginxProcess.stop(); testSmartNginx.nginxProcess.stop();
}); });
tap.start(); export default tap.start();

View File

@@ -1,8 +1,8 @@
/** /**
* autocreated commitinfo by @pushrocks/commitinfo * autocreated commitinfo by @push.rocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartnginx', name: '@push.rocks/smartnginx',
version: '2.0.52', version: '2.0.53',
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.'
} }

View File

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

@@ -116,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
@@ -129,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,19 +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 '@push.rocks/lik'; import * as lik from '@push.rocks/lik';
import * as smartfile from '@push.rocks/smartfile'; import * as smartfs from '@push.rocks/smartfs';
import * as smartlog from '@push.rocks/smartlog'; import * as smartlog from '@push.rocks/smartlog';
import * as smartpath from '@push.rocks/smartpath'; import * as smartpath from '@push.rocks/smartpath';
import * as smartpromise from '@push.rocks/smartpromise'; import * as smartpromise from '@push.rocks/smartpromise';
import * as smartshell from '@push.rocks/smartshell'; import * as smartshell from '@push.rocks/smartshell';
import * as smartstring from '@push.rocks/smartstring'; import * as smartstring from '@push.rocks/smartstring';
import * as smartunique from '@push.rocks/smartunique'; import * as smartunique from '@push.rocks/smartunique';
export { lik, smartfile, smartlog, smartpath, smartpromise, smartshell, 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

@@ -3,9 +3,12 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"useDefineForClassFields": false, "useDefineForClassFields": false,
"target": "ES2022", "target": "ES2022",
"module": "ES2022", "module": "NodeNext",
"moduleResolution": "nodenext", "moduleResolution": "NodeNext",
"esModuleInterop": true, "esModuleInterop": true,
"verbatimModuleSyntax": true, "verbatimModuleSyntax": true
} },
"exclude": [
"dist_*/**/*.d.ts"
]
} }