@push.rocks/smartproxy 13.1.2 → 13.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/package.json +1 -1
- package/readme.md +437 -226
- package/ts/00_commitinfo_data.ts +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartproxy',
|
|
6
|
-
version: '13.1.
|
|
6
|
+
version: '13.1.3',
|
|
7
7
|
description: 'A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx3QkFBd0I7SUFDOUIsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLG1PQUFtTztDQUNqUCxDQUFBIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartproxy",
|
|
3
|
-
"version": "13.1.
|
|
3
|
+
"version": "13.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.",
|
|
6
6
|
"main": "dist_ts/index.js",
|
package/readme.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# @push.rocks/smartproxy
|
|
2
2
|
|
|
3
|
-
A high-performance proxy toolkit for Node.js,
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
- Advanced TCP/SNI-based
|
|
9
|
-
-
|
|
3
|
+
A unified high-performance proxy toolkit for Node.js, with **SmartProxy** as the central API to handle all your proxy needs:
|
|
4
|
+
|
|
5
|
+
- **Unified Configuration API**: One consistent way to configure various proxy types
|
|
6
|
+
- **SSL/TLS Support**: Automatic HTTPS with Let's Encrypt certificate provisioning
|
|
7
|
+
- **Simplified Domain Management**: Easy routing based on domain names with wildcard support
|
|
8
|
+
- **Advanced SNI Handling**: Smart TCP/SNI-based forwarding with IP filtering
|
|
9
|
+
- **Multiple Forwarding Types**: HTTP-only, HTTPS passthrough, TLS termination options
|
|
10
|
+
- **Security Features**: IP allowlists, connection limits, timeouts, and more
|
|
10
11
|
|
|
11
12
|
## Project Architecture Overview
|
|
12
13
|
|
|
@@ -51,34 +52,52 @@ SmartProxy has been restructured using a modern, modular architecture to improve
|
|
|
51
52
|
└── /redirects # Redirect handlers
|
|
52
53
|
```
|
|
53
54
|
|
|
54
|
-
##
|
|
55
|
-
|
|
55
|
+
## Main Components
|
|
56
|
+
|
|
57
|
+
### Primary API (Recommended)
|
|
58
|
+
|
|
59
|
+
- **SmartProxy** (`ts/proxies/smart-proxy/smart-proxy.ts`)
|
|
60
|
+
The central unified API for all proxy needs, featuring:
|
|
61
|
+
- Domain-based routing with SNI inspection
|
|
62
|
+
- Automatic certificate management
|
|
63
|
+
- Multiple forwarding types in one configuration
|
|
64
|
+
- Advanced security controls
|
|
65
|
+
- Flexible backend targeting options
|
|
66
|
+
|
|
67
|
+
### Helper Functions
|
|
68
|
+
|
|
69
|
+
- **createDomainConfig**
|
|
70
|
+
Create domain configuration with clean syntax
|
|
71
|
+
- **httpOnly**, **httpsPassthrough**, **tlsTerminateToHttp**, **tlsTerminateToHttps**
|
|
72
|
+
Helper functions to create different forwarding configurations
|
|
73
|
+
|
|
74
|
+
### Specialized Components
|
|
56
75
|
|
|
57
76
|
- **NetworkProxy** (`ts/proxies/network-proxy/network-proxy.ts`)
|
|
58
|
-
HTTP/HTTPS reverse proxy with TLS termination
|
|
59
|
-
connection pooling, and optional ACME integration.
|
|
77
|
+
HTTP/HTTPS reverse proxy with TLS termination and WebSocket support
|
|
60
78
|
- **Port80Handler** (`ts/http/port80/port80-handler.ts`)
|
|
61
|
-
ACME HTTP-01 challenge handler
|
|
79
|
+
ACME HTTP-01 challenge handler for Let's Encrypt certificates
|
|
62
80
|
- **NfTablesProxy** (`ts/proxies/nftables-proxy/nftables-proxy.ts`)
|
|
63
|
-
Low-level port forwarding using nftables NAT rules
|
|
81
|
+
Low-level port forwarding using nftables NAT rules
|
|
64
82
|
- **Redirect**, **SslRedirect** (`ts/http/redirects/redirect-handler.ts`)
|
|
65
|
-
HTTP
|
|
66
|
-
- **SmartProxy** (`ts/proxies/smart-proxy/smart-proxy.ts`)
|
|
67
|
-
TCP/SNI-based proxy with dynamic routing, IP filtering, and unified certificates.
|
|
83
|
+
HTTP-to-HTTPS redirects with customizable rules
|
|
68
84
|
- **SniHandler** (`ts/tls/sni/sni-handler.ts`)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
Utilities for SNI extraction from TLS handshakes
|
|
86
|
+
|
|
87
|
+
### Core Utilities
|
|
88
|
+
|
|
89
|
+
- **ValidationUtils** (`ts/core/utils/validation-utils.ts`)
|
|
90
|
+
Domain, port, and configuration validation
|
|
91
|
+
- **IpUtils** (`ts/core/utils/ip-utils.ts`)
|
|
92
|
+
IP address validation and filtering with glob patterns
|
|
93
|
+
|
|
94
|
+
### Interfaces and Types
|
|
95
|
+
|
|
96
|
+
- `ISmartProxyOptions`, `IDomainConfig` (`ts/proxies/smart-proxy/models/interfaces.ts`)
|
|
97
|
+
- `IForwardConfig`, `TForwardingType` (`ts/forwarding/config/forwarding-types.ts`)
|
|
98
|
+
- `INetworkProxyOptions` (`ts/proxies/network-proxy/models/types.ts`)
|
|
99
|
+
- `IAcmeOptions`, `IDomainOptions` (`ts/certificate/models/certificate-types.ts`)
|
|
100
|
+
- `INfTableProxySettings` (`ts/proxies/nftables-proxy/models/interfaces.ts`)
|
|
82
101
|
|
|
83
102
|
## Installation
|
|
84
103
|
Install via npm:
|
|
@@ -86,15 +105,142 @@ Install via npm:
|
|
|
86
105
|
npm install @push.rocks/smartproxy
|
|
87
106
|
```
|
|
88
107
|
|
|
89
|
-
## Quick Start
|
|
108
|
+
## Quick Start with SmartProxy
|
|
109
|
+
|
|
110
|
+
SmartProxy is the recommended way to use this library, providing a unified API for all proxy scenarios.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { SmartProxy, createDomainConfig, httpOnly, tlsTerminateToHttp, httpsPassthrough } from '@push.rocks/smartproxy';
|
|
114
|
+
|
|
115
|
+
// Create a new SmartProxy instance with all your domain configurations in one place
|
|
116
|
+
const proxy = new SmartProxy({
|
|
117
|
+
// Listen on port 443 for incoming connections
|
|
118
|
+
fromPort: 443,
|
|
119
|
+
|
|
120
|
+
// Configure domains and their forwarding rules
|
|
121
|
+
domainConfigs: [
|
|
122
|
+
// Basic HTTP forwarding for api.example.com
|
|
123
|
+
createDomainConfig('api.example.com', httpOnly({
|
|
124
|
+
target: { host: 'localhost', port: 3000 }
|
|
125
|
+
})),
|
|
126
|
+
|
|
127
|
+
// HTTPS termination with automatic Let's Encrypt certificates
|
|
128
|
+
createDomainConfig('secure.example.com', tlsTerminateToHttp({
|
|
129
|
+
target: { host: 'localhost', port: 8080 },
|
|
130
|
+
acme: {
|
|
131
|
+
enabled: true,
|
|
132
|
+
production: true
|
|
133
|
+
}
|
|
134
|
+
})),
|
|
135
|
+
|
|
136
|
+
// Multiple domains with wildcard support
|
|
137
|
+
createDomainConfig(['example.com', '*.example.com'], httpsPassthrough({
|
|
138
|
+
target: {
|
|
139
|
+
// Load balancing across multiple backend servers
|
|
140
|
+
host: ['192.168.1.10', '192.168.1.11'],
|
|
141
|
+
port: 443
|
|
142
|
+
},
|
|
143
|
+
security: {
|
|
144
|
+
// IP filtering for enhanced security
|
|
145
|
+
allowedIps: ['10.0.0.*', '192.168.1.*'],
|
|
146
|
+
blockedIps: ['1.2.3.4']
|
|
147
|
+
}
|
|
148
|
+
}))
|
|
149
|
+
],
|
|
150
|
+
|
|
151
|
+
// Enable SNI-based routing
|
|
152
|
+
sniEnabled: true,
|
|
153
|
+
|
|
154
|
+
// Automatic Let's Encrypt integration
|
|
155
|
+
acme: {
|
|
156
|
+
enabled: true,
|
|
157
|
+
contactEmail: 'admin@example.com',
|
|
158
|
+
useProduction: true
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Listen for certificate events
|
|
163
|
+
proxy.on('certificate', evt => {
|
|
164
|
+
console.log(`Certificate for ${evt.domain} ready, expires: ${evt.expiryDate}`);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Start the proxy
|
|
168
|
+
await proxy.start();
|
|
169
|
+
|
|
170
|
+
// Dynamically add or update domain configurations later
|
|
171
|
+
await proxy.updateDomainConfigs([
|
|
172
|
+
createDomainConfig('new-domain.com', tlsTerminateToHttp({
|
|
173
|
+
target: { host: 'localhost', port: 9000 }
|
|
174
|
+
}))
|
|
175
|
+
]);
|
|
176
|
+
|
|
177
|
+
// Later, gracefully shut down
|
|
178
|
+
await proxy.stop();
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### What You Can Do with SmartProxy
|
|
182
|
+
|
|
183
|
+
1. **Domain-Based Routing**
|
|
184
|
+
```typescript
|
|
185
|
+
// Route requests for different domains to different backend servers
|
|
186
|
+
createDomainConfig('api.example.com', httpOnly({
|
|
187
|
+
target: { host: 'api-server', port: 3000 }
|
|
188
|
+
}))
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
2. **Automatic SSL with Let's Encrypt**
|
|
192
|
+
```typescript
|
|
193
|
+
// Get and automatically renew certificates
|
|
194
|
+
createDomainConfig('secure.example.com', tlsTerminateToHttp({
|
|
195
|
+
target: { host: 'localhost', port: 8080 },
|
|
196
|
+
acme: { enabled: true, production: true }
|
|
197
|
+
}))
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
3. **Load Balancing**
|
|
201
|
+
```typescript
|
|
202
|
+
// Distribute traffic across multiple backend servers
|
|
203
|
+
createDomainConfig('app.example.com', httpOnly({
|
|
204
|
+
target: {
|
|
205
|
+
host: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
|
|
206
|
+
port: 8080
|
|
207
|
+
}
|
|
208
|
+
}))
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
4. **Security Controls**
|
|
212
|
+
```typescript
|
|
213
|
+
// Restrict access based on IP addresses
|
|
214
|
+
createDomainConfig('admin.example.com', httpOnly({
|
|
215
|
+
target: { host: 'localhost', port: 8080 },
|
|
216
|
+
security: {
|
|
217
|
+
allowedIps: ['10.0.0.*', '192.168.1.*'],
|
|
218
|
+
maxConnections: 100
|
|
219
|
+
}
|
|
220
|
+
}))
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
5. **Wildcard Domains**
|
|
224
|
+
```typescript
|
|
225
|
+
// Handle all subdomains with one config
|
|
226
|
+
createDomainConfig(['example.com', '*.example.com'], httpsPassthrough({
|
|
227
|
+
target: { host: 'backend-server', port: 443 }
|
|
228
|
+
}))
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Other Components
|
|
232
|
+
|
|
233
|
+
While SmartProxy provides a unified API for most needs, you can also use individual components:
|
|
234
|
+
|
|
235
|
+
### NetworkProxy
|
|
236
|
+
For HTTP/HTTPS reverse proxy with TLS termination and WebSocket support:
|
|
90
237
|
|
|
91
|
-
### 1. HTTP(S) Reverse Proxy (NetworkProxy)
|
|
92
238
|
```typescript
|
|
93
239
|
import { NetworkProxy } from '@push.rocks/smartproxy';
|
|
240
|
+
import * as fs from 'fs';
|
|
94
241
|
|
|
95
242
|
const proxy = new NetworkProxy({ port: 443 });
|
|
96
243
|
await proxy.start();
|
|
97
|
-
|
|
98
244
|
await proxy.updateProxyConfigs([
|
|
99
245
|
{
|
|
100
246
|
hostName: 'example.com',
|
|
@@ -104,154 +250,47 @@ await proxy.updateProxyConfigs([
|
|
|
104
250
|
privateKey: fs.readFileSync('key.pem', 'utf8'),
|
|
105
251
|
}
|
|
106
252
|
]);
|
|
107
|
-
|
|
108
|
-
// Add default headers to all responses
|
|
109
|
-
await proxy.addDefaultHeaders({
|
|
110
|
-
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
|
|
111
|
-
});
|
|
112
|
-
// ...
|
|
113
|
-
await proxy.stop();
|
|
114
253
|
```
|
|
115
254
|
|
|
116
|
-
###
|
|
117
|
-
|
|
118
|
-
import { Redirect, SslRedirect } from '@push.rocks/smartproxy';
|
|
119
|
-
import * as fs from 'fs';
|
|
120
|
-
|
|
121
|
-
// Custom redirect rules
|
|
122
|
-
const redirect = new Redirect({
|
|
123
|
-
httpPort: 80,
|
|
124
|
-
httpsPort: 443,
|
|
125
|
-
sslOptions: {
|
|
126
|
-
key: fs.readFileSync('key.pem'),
|
|
127
|
-
cert: fs.readFileSync('cert.pem'),
|
|
128
|
-
},
|
|
129
|
-
rules: [
|
|
130
|
-
{
|
|
131
|
-
fromProtocol: 'http',
|
|
132
|
-
fromHost: '*',
|
|
133
|
-
toProtocol: 'https',
|
|
134
|
-
toHost: '$1',
|
|
135
|
-
statusCode: 301
|
|
136
|
-
}
|
|
137
|
-
]
|
|
138
|
-
});
|
|
139
|
-
await redirect.start();
|
|
140
|
-
|
|
141
|
-
// Quick HTTP→HTTPS helper on port 80
|
|
142
|
-
const quick = new SslRedirect(80);
|
|
143
|
-
await quick.start();
|
|
144
|
-
```
|
|
255
|
+
### Port80Handler
|
|
256
|
+
For standalone ACME certificate management:
|
|
145
257
|
|
|
146
|
-
### 3. Automatic Certificates (ACME Port80Handler)
|
|
147
258
|
```typescript
|
|
148
259
|
import { Port80Handler } from '@push.rocks/smartproxy';
|
|
149
260
|
|
|
150
|
-
// Configure ACME on port 80 with contact email
|
|
151
261
|
const acme = new Port80Handler({
|
|
152
262
|
port: 80,
|
|
153
263
|
contactEmail: 'admin@example.com',
|
|
154
|
-
useProduction: true
|
|
155
|
-
renewThresholdDays: 30
|
|
156
|
-
});
|
|
157
|
-
acme.on('certificate-issued', evt => {
|
|
158
|
-
console.log(`Certificate ready for ${evt.domain}, expires ${evt.expiryDate}`);
|
|
264
|
+
useProduction: true
|
|
159
265
|
});
|
|
266
|
+
acme.on('certificate-issued', evt => console.log(`Certificate ready: ${evt.domain}`));
|
|
160
267
|
await acme.start();
|
|
161
|
-
acme.addDomain({
|
|
162
|
-
domainName: 'example.com',
|
|
163
|
-
sslRedirect: true,
|
|
164
|
-
acmeMaintenance: true
|
|
165
|
-
});
|
|
166
268
|
```
|
|
167
269
|
|
|
168
|
-
###
|
|
270
|
+
### NfTablesProxy
|
|
271
|
+
For low-level port forwarding using nftables:
|
|
272
|
+
|
|
169
273
|
```typescript
|
|
170
274
|
import { NfTablesProxy } from '@push.rocks/smartproxy';
|
|
171
275
|
|
|
172
|
-
// Forward port 80→8080 with source IP preservation
|
|
173
276
|
const nft = new NfTablesProxy({
|
|
174
277
|
fromPort: 80,
|
|
175
278
|
toPort: 8080,
|
|
176
279
|
toHost: 'localhost',
|
|
177
|
-
preserveSourceIP: true
|
|
178
|
-
deleteOnExit: true
|
|
280
|
+
preserveSourceIP: true
|
|
179
281
|
});
|
|
180
282
|
await nft.start();
|
|
181
|
-
// ...
|
|
182
|
-
await nft.stop();
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### 5. TCP/SNI Proxy (SmartProxy)
|
|
186
|
-
```typescript
|
|
187
|
-
import { SmartProxy } from '@push.rocks/smartproxy';
|
|
188
|
-
import { createDomainConfig, httpOnly, tlsTerminateToHttp, httpsPassthrough } from '@push.rocks/smartproxy';
|
|
189
|
-
|
|
190
|
-
const smart = new SmartProxy({
|
|
191
|
-
fromPort: 443,
|
|
192
|
-
toPort: 8443,
|
|
193
|
-
domainConfigs: [
|
|
194
|
-
// HTTPS passthrough example
|
|
195
|
-
createDomainConfig(['example.com', '*.example.com'],
|
|
196
|
-
httpsPassthrough({
|
|
197
|
-
target: {
|
|
198
|
-
host: '127.0.0.1',
|
|
199
|
-
port: 443
|
|
200
|
-
},
|
|
201
|
-
security: {
|
|
202
|
-
allowedIps: ['*']
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
),
|
|
206
|
-
// HTTPS termination example
|
|
207
|
-
createDomainConfig('secure.example.com',
|
|
208
|
-
tlsTerminateToHttp({
|
|
209
|
-
target: {
|
|
210
|
-
host: 'localhost',
|
|
211
|
-
port: 3000
|
|
212
|
-
},
|
|
213
|
-
acme: {
|
|
214
|
-
enabled: true,
|
|
215
|
-
production: true
|
|
216
|
-
}
|
|
217
|
-
})
|
|
218
|
-
)
|
|
219
|
-
],
|
|
220
|
-
sniEnabled: true
|
|
221
|
-
});
|
|
222
|
-
smart.on('certificate', evt => console.log(evt));
|
|
223
|
-
await smart.start();
|
|
224
|
-
// Update domains later
|
|
225
|
-
await smart.updateDomainConfigs([/* new configs */]);
|
|
226
283
|
```
|
|
227
284
|
|
|
228
|
-
###
|
|
229
|
-
|
|
230
|
-
import { SniHandler } from '@push.rocks/smartproxy';
|
|
231
|
-
|
|
232
|
-
// Extract SNI from a TLS ClientHello buffer
|
|
233
|
-
const sni = SniHandler.extractSNI(buffer);
|
|
234
|
-
|
|
235
|
-
// Reassemble fragmented ClientHello
|
|
236
|
-
const complete = SniHandler.handleFragmentedClientHello(buf, connId);
|
|
237
|
-
```
|
|
285
|
+
### Redirect / SslRedirect
|
|
286
|
+
For HTTP-to-HTTPS redirects:
|
|
238
287
|
|
|
239
|
-
### 7. Core Utilities (ValidationUtils, IpUtils)
|
|
240
288
|
```typescript
|
|
241
|
-
import {
|
|
242
|
-
|
|
243
|
-
// Validate a domain name
|
|
244
|
-
const isValidDomain = ValidationUtils.isValidDomainName('example.com');
|
|
289
|
+
import { SslRedirect } from '@push.rocks/smartproxy';
|
|
245
290
|
|
|
246
|
-
//
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
['192.168.1.*'], // allowed IPs
|
|
250
|
-
['192.168.1.100'] // blocked IPs
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
// Convert CIDR to glob patterns
|
|
254
|
-
const globPatterns = IpUtils.cidrToGlobPatterns('10.0.0.0/24');
|
|
291
|
+
// Quick HTTP→HTTPS helper on port 80
|
|
292
|
+
const redirect = new SslRedirect(80);
|
|
293
|
+
await redirect.start();
|
|
255
294
|
```
|
|
256
295
|
|
|
257
296
|
## API Reference
|
|
@@ -479,113 +518,285 @@ Listen for certificate events via EventEmitter:
|
|
|
479
518
|
|
|
480
519
|
Provide a `certProvisionFunction(domain)` in SmartProxy settings to supply static certs or return `'http01'`.
|
|
481
520
|
|
|
482
|
-
##
|
|
521
|
+
## SmartProxy: Common Use Cases
|
|
483
522
|
|
|
484
|
-
The SmartProxy
|
|
523
|
+
The SmartProxy component offers a clean, unified approach to handle virtually any proxy scenario.
|
|
485
524
|
|
|
486
|
-
###
|
|
525
|
+
### 1. API Gateway / Backend Routing
|
|
487
526
|
|
|
488
|
-
|
|
527
|
+
Create a flexible API gateway to route traffic to different microservices based on domain:
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
import { SmartProxy, createDomainConfig, httpOnly, tlsTerminateToHttp } from '@push.rocks/smartproxy';
|
|
531
|
+
|
|
532
|
+
const apiGateway = new SmartProxy({
|
|
533
|
+
fromPort: 443,
|
|
534
|
+
domainConfigs: [
|
|
535
|
+
// Users API
|
|
536
|
+
createDomainConfig('users.api.example.com', tlsTerminateToHttp({
|
|
537
|
+
target: { host: 'users-service', port: 3000 },
|
|
538
|
+
acme: { enabled: true, production: true }
|
|
539
|
+
})),
|
|
540
|
+
|
|
541
|
+
// Products API
|
|
542
|
+
createDomainConfig('products.api.example.com', tlsTerminateToHttp({
|
|
543
|
+
target: { host: 'products-service', port: 3001 },
|
|
544
|
+
acme: { enabled: true, production: true }
|
|
545
|
+
})),
|
|
546
|
+
|
|
547
|
+
// Admin dashboard gets extra security
|
|
548
|
+
createDomainConfig('admin.example.com', tlsTerminateToHttp({
|
|
549
|
+
target: { host: 'admin-dashboard', port: 8080 },
|
|
550
|
+
security: {
|
|
551
|
+
allowedIps: ['10.0.0.*', '192.168.1.*'] // Only allow internal network
|
|
552
|
+
}
|
|
553
|
+
}))
|
|
554
|
+
],
|
|
555
|
+
sniEnabled: true
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
await apiGateway.start();
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
### 2. Automatic HTTPS for Development
|
|
562
|
+
|
|
563
|
+
Easily add HTTPS to your local development environment with automatic certificates:
|
|
564
|
+
|
|
565
|
+
```typescript
|
|
566
|
+
import { SmartProxy, createDomainConfig, tlsTerminateToHttp } from '@push.rocks/smartproxy';
|
|
567
|
+
|
|
568
|
+
const devProxy = new SmartProxy({
|
|
569
|
+
fromPort: 443,
|
|
570
|
+
domainConfigs: [
|
|
571
|
+
createDomainConfig('dev.local', tlsTerminateToHttp({
|
|
572
|
+
target: { host: 'localhost', port: 3000 },
|
|
573
|
+
// For development, use self-signed or existing certificates
|
|
574
|
+
https: {
|
|
575
|
+
customCert: {
|
|
576
|
+
key: fs.readFileSync('dev-cert.key', 'utf8'),
|
|
577
|
+
cert: fs.readFileSync('dev-cert.pem', 'utf8')
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
// Auto-redirect HTTP to HTTPS
|
|
581
|
+
http: {
|
|
582
|
+
enabled: true,
|
|
583
|
+
redirectToHttps: true
|
|
584
|
+
}
|
|
585
|
+
}))
|
|
586
|
+
]
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
await devProxy.start();
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
### 3. Load Balancing Multiple Servers
|
|
593
|
+
|
|
594
|
+
Distribute traffic across multiple backend servers with round-robin load balancing:
|
|
595
|
+
|
|
596
|
+
```typescript
|
|
597
|
+
import { SmartProxy, createDomainConfig, tlsTerminateToHttp } from '@push.rocks/smartproxy';
|
|
598
|
+
|
|
599
|
+
const loadBalancer = new SmartProxy({
|
|
600
|
+
fromPort: 443,
|
|
601
|
+
domainConfigs: [
|
|
602
|
+
createDomainConfig('app.example.com', tlsTerminateToHttp({
|
|
603
|
+
target: {
|
|
604
|
+
// Round-robin across multiple servers
|
|
605
|
+
host: [
|
|
606
|
+
'10.0.0.10',
|
|
607
|
+
'10.0.0.11',
|
|
608
|
+
'10.0.0.12'
|
|
609
|
+
],
|
|
610
|
+
port: 8080
|
|
611
|
+
},
|
|
612
|
+
acme: { enabled: true, production: true }
|
|
613
|
+
}))
|
|
614
|
+
]
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
await loadBalancer.start();
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
### 4. Wildcard Subdomain Handling
|
|
621
|
+
|
|
622
|
+
Support multiple or dynamically created subdomains with one configuration:
|
|
623
|
+
|
|
624
|
+
```typescript
|
|
625
|
+
import { SmartProxy, createDomainConfig, tlsTerminateToHttp } from '@push.rocks/smartproxy';
|
|
626
|
+
|
|
627
|
+
const multiTenantProxy = new SmartProxy({
|
|
628
|
+
fromPort: 443,
|
|
629
|
+
domainConfigs: [
|
|
630
|
+
// Handle all customer subdomains with one config
|
|
631
|
+
createDomainConfig('*.example.com', tlsTerminateToHttp({
|
|
632
|
+
target: { host: 'tenant-router', port: 8080 },
|
|
633
|
+
acme: { enabled: true, production: true },
|
|
634
|
+
// Pass original hostname to backend for tenant identification
|
|
635
|
+
advanced: {
|
|
636
|
+
headers: {
|
|
637
|
+
'X-Original-Host': '{sni}'
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}))
|
|
641
|
+
],
|
|
642
|
+
sniEnabled: true
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
await multiTenantProxy.start();
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
### 5. Comprehensive Proxy Server
|
|
649
|
+
|
|
650
|
+
Create a complete proxy solution with multiple services on a single server:
|
|
651
|
+
|
|
652
|
+
```typescript
|
|
653
|
+
import { SmartProxy, createDomainConfig, httpOnly, tlsTerminateToHttp, tlsTerminateToHttps, httpsPassthrough } from '@push.rocks/smartproxy';
|
|
654
|
+
|
|
655
|
+
const enterpriseProxy = new SmartProxy({
|
|
656
|
+
fromPort: 443,
|
|
657
|
+
domainConfigs: [
|
|
658
|
+
// Web application with automatic HTTPS
|
|
659
|
+
createDomainConfig('app.example.com', tlsTerminateToHttp({
|
|
660
|
+
target: { host: 'web-app', port: 8080 },
|
|
661
|
+
acme: { enabled: true, production: true },
|
|
662
|
+
http: { enabled: true, redirectToHttps: true }
|
|
663
|
+
})),
|
|
664
|
+
|
|
665
|
+
// Legacy system that needs HTTPS passthrough
|
|
666
|
+
createDomainConfig('legacy.example.com', httpsPassthrough({
|
|
667
|
+
target: { host: 'legacy-server', port: 443 }
|
|
668
|
+
})),
|
|
669
|
+
|
|
670
|
+
// Internal APIs with IP restrictions
|
|
671
|
+
createDomainConfig('api.internal.example.com', tlsTerminateToHttp({
|
|
672
|
+
target: { host: 'api-gateway', port: 3000 },
|
|
673
|
+
security: {
|
|
674
|
+
allowedIps: ['10.0.0.0/16', '192.168.0.0/16'],
|
|
675
|
+
maxConnections: 500
|
|
676
|
+
}
|
|
677
|
+
})),
|
|
678
|
+
|
|
679
|
+
// External services with customer certificate
|
|
680
|
+
createDomainConfig('external.example.com', tlsTerminateToHttps({
|
|
681
|
+
target: { host: 'external-service', port: 8443 },
|
|
682
|
+
https: {
|
|
683
|
+
customCert: {
|
|
684
|
+
key: fs.readFileSync('external-key.pem', 'utf8'),
|
|
685
|
+
cert: fs.readFileSync('external-cert.pem', 'utf8')
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}))
|
|
689
|
+
],
|
|
690
|
+
sniEnabled: true,
|
|
691
|
+
// Enable connection timeouts for security
|
|
692
|
+
inactivityTimeout: 30000,
|
|
693
|
+
// Using global certificate management
|
|
694
|
+
acme: {
|
|
695
|
+
enabled: true,
|
|
696
|
+
contactEmail: 'admin@example.com',
|
|
697
|
+
useProduction: true,
|
|
698
|
+
renewThresholdDays: 30
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
await enterpriseProxy.start();
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
## Unified Forwarding System Details
|
|
706
|
+
|
|
707
|
+
SmartProxy's unified forwarding system supports four primary forwarding types:
|
|
489
708
|
|
|
490
709
|
1. **HTTP-only (`http-only`)**: Forwards HTTP traffic to a backend server.
|
|
491
710
|
2. **HTTPS Passthrough (`https-passthrough`)**: Passes through raw TLS traffic without termination (SNI forwarding).
|
|
492
711
|
3. **HTTPS Termination to HTTP (`https-terminate-to-http`)**: Terminates TLS and forwards the decrypted traffic to an HTTP backend.
|
|
493
712
|
4. **HTTPS Termination to HTTPS (`https-terminate-to-https`)**: Terminates TLS and creates a new TLS connection to an HTTPS backend.
|
|
494
713
|
|
|
495
|
-
###
|
|
714
|
+
### Configuration Format
|
|
496
715
|
|
|
497
716
|
Each domain is configured with a forwarding type and target:
|
|
498
717
|
|
|
499
718
|
```typescript
|
|
500
719
|
{
|
|
501
|
-
domains: ['example.com'],
|
|
720
|
+
domains: ['example.com'], // Single domain or array of domains (with wildcard support)
|
|
502
721
|
forwarding: {
|
|
503
|
-
type: 'http-only',
|
|
722
|
+
type: 'http-only', // One of the four forwarding types
|
|
504
723
|
target: {
|
|
505
|
-
host: 'localhost',
|
|
506
|
-
port: 3000
|
|
724
|
+
host: 'localhost', // Backend server (string or array for load balancing)
|
|
725
|
+
port: 3000 // Backend port
|
|
507
726
|
}
|
|
727
|
+
// Additional options as needed
|
|
508
728
|
}
|
|
509
729
|
}
|
|
510
730
|
```
|
|
511
731
|
|
|
512
732
|
### Helper Functions
|
|
513
733
|
|
|
514
|
-
Helper functions
|
|
734
|
+
Helper functions provide a cleaner syntax for creating configurations:
|
|
515
735
|
|
|
516
736
|
```typescript
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
)
|
|
526
|
-
|
|
527
|
-
// HTTPS termination to HTTP
|
|
528
|
-
await domainManager.addDomainConfig(
|
|
529
|
-
createDomainConfig('secure.example.com', tlsTerminateToHttp({
|
|
530
|
-
target: { host: 'localhost', port: 3000 },
|
|
531
|
-
acme: { production: true }
|
|
532
|
-
}))
|
|
533
|
-
);
|
|
534
|
-
|
|
535
|
-
// HTTPS termination to HTTPS
|
|
536
|
-
await domainManager.addDomainConfig(
|
|
537
|
-
createDomainConfig('api.example.com', tlsTerminateToHttps({
|
|
538
|
-
target: { host: 'internal-api', port: 8443 },
|
|
539
|
-
http: { redirectToHttps: true }
|
|
540
|
-
}))
|
|
541
|
-
);
|
|
542
|
-
|
|
543
|
-
// HTTPS passthrough (SNI)
|
|
544
|
-
await domainManager.addDomainConfig(
|
|
545
|
-
createDomainConfig('passthrough.example.com', httpsPassthrough({
|
|
546
|
-
target: { host: '10.0.0.5', port: 443 }
|
|
547
|
-
}))
|
|
548
|
-
);
|
|
737
|
+
// Instead of manually specifying the type and format
|
|
738
|
+
const config = createDomainConfig('example.com', httpOnly({
|
|
739
|
+
target: { host: 'localhost', port: 3000 }
|
|
740
|
+
}));
|
|
741
|
+
|
|
742
|
+
// Available helper functions:
|
|
743
|
+
// - httpOnly() - For HTTP-only traffic
|
|
744
|
+
// - httpsPassthrough() - For SNI-based passthrough
|
|
745
|
+
// - tlsTerminateToHttp() - For HTTPS termination to HTTP
|
|
746
|
+
// - tlsTerminateToHttps() - For HTTPS termination to HTTPS
|
|
549
747
|
```
|
|
550
748
|
|
|
551
|
-
### Advanced Configuration
|
|
749
|
+
### Advanced Configuration Options
|
|
552
750
|
|
|
553
751
|
For more complex scenarios, additional options can be specified:
|
|
554
752
|
|
|
555
753
|
```typescript
|
|
556
|
-
{
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
754
|
+
createDomainConfig('api.example.com', tlsTerminateToHttps({
|
|
755
|
+
// Target configuration with load balancing
|
|
756
|
+
target: {
|
|
757
|
+
host: ['10.0.0.10', '10.0.0.11'], // Round-robin load balancing
|
|
758
|
+
port: 8443
|
|
759
|
+
},
|
|
760
|
+
|
|
761
|
+
// HTTP options
|
|
762
|
+
http: {
|
|
763
|
+
enabled: true, // Listen on HTTP port
|
|
764
|
+
redirectToHttps: true // Automatically redirect to HTTPS
|
|
765
|
+
},
|
|
766
|
+
|
|
767
|
+
// HTTPS/TLS options
|
|
768
|
+
https: {
|
|
769
|
+
customCert: { // Provide your own certificate
|
|
770
|
+
key: '-----BEGIN PRIVATE KEY-----\n...',
|
|
771
|
+
cert: '-----BEGIN CERTIFICATE-----\n...'
|
|
574
772
|
},
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
773
|
+
forwardSni: true // Forward original SNI to backend
|
|
774
|
+
},
|
|
775
|
+
|
|
776
|
+
// Let's Encrypt ACME integration
|
|
777
|
+
acme: {
|
|
778
|
+
enabled: true, // Enable automatic certificates
|
|
779
|
+
production: true, // Use production Let's Encrypt
|
|
780
|
+
maintenance: true // Auto-renew certificates
|
|
781
|
+
},
|
|
782
|
+
|
|
783
|
+
// Security settings
|
|
784
|
+
security: {
|
|
785
|
+
allowedIps: ['10.0.0.*'], // IP allowlist (glob patterns)
|
|
786
|
+
blockedIps: ['1.2.3.4'], // IP blocklist
|
|
787
|
+
maxConnections: 100 // Connection limits
|
|
788
|
+
},
|
|
789
|
+
|
|
790
|
+
// Advanced settings
|
|
791
|
+
advanced: {
|
|
792
|
+
timeout: 30000, // Connection timeout in ms
|
|
793
|
+
headers: { // Custom headers to backend
|
|
794
|
+
'X-Forwarded-For': '{clientIp}',
|
|
795
|
+
'X-Original-Host': '{sni}' // Template variables available
|
|
579
796
|
},
|
|
580
|
-
|
|
581
|
-
timeout: 30000,
|
|
582
|
-
headers: {
|
|
583
|
-
'X-Forwarded-For': '{clientIp}',
|
|
584
|
-
'X-Original-Host': '{sni}'
|
|
585
|
-
}
|
|
586
|
-
}
|
|
797
|
+
keepAlive: true // Keep connections alive
|
|
587
798
|
}
|
|
588
|
-
}
|
|
799
|
+
}))
|
|
589
800
|
```
|
|
590
801
|
|
|
591
802
|
### Extended Configuration Options
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartproxy',
|
|
6
|
-
version: '13.1.
|
|
6
|
+
version: '13.1.3',
|
|
7
7
|
description: 'A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.'
|
|
8
8
|
}
|