@push.rocks/smartproxy 15.0.2 → 16.0.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.
Files changed (160) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/certificate/index.d.ts +10 -4
  3. package/dist_ts/certificate/index.js +5 -7
  4. package/dist_ts/certificate/models/certificate-types.d.ts +35 -15
  5. package/dist_ts/certificate/providers/cert-provisioner.d.ts +41 -15
  6. package/dist_ts/certificate/providers/cert-provisioner.js +201 -41
  7. package/dist_ts/core/models/index.d.ts +2 -0
  8. package/dist_ts/core/models/index.js +3 -1
  9. package/dist_ts/core/models/route-context.d.ts +62 -0
  10. package/dist_ts/core/models/route-context.js +43 -0
  11. package/dist_ts/core/models/socket-augmentation.d.ts +12 -0
  12. package/dist_ts/core/models/socket-augmentation.js +18 -0
  13. package/dist_ts/core/utils/event-system.d.ts +200 -0
  14. package/dist_ts/core/utils/event-system.js +224 -0
  15. package/dist_ts/core/utils/index.d.ts +7 -0
  16. package/dist_ts/core/utils/index.js +8 -1
  17. package/dist_ts/core/utils/route-manager.d.ts +118 -0
  18. package/dist_ts/core/utils/route-manager.js +383 -0
  19. package/dist_ts/core/utils/route-utils.d.ts +94 -0
  20. package/dist_ts/core/utils/route-utils.js +264 -0
  21. package/dist_ts/core/utils/security-utils.d.ts +111 -0
  22. package/dist_ts/core/utils/security-utils.js +212 -0
  23. package/dist_ts/core/utils/shared-security-manager.d.ts +110 -0
  24. package/dist_ts/core/utils/shared-security-manager.js +252 -0
  25. package/dist_ts/core/utils/template-utils.d.ts +37 -0
  26. package/dist_ts/core/utils/template-utils.js +104 -0
  27. package/dist_ts/core/utils/websocket-utils.d.ts +23 -0
  28. package/dist_ts/core/utils/websocket-utils.js +86 -0
  29. package/dist_ts/forwarding/config/forwarding-types.d.ts +40 -76
  30. package/dist_ts/forwarding/config/forwarding-types.js +19 -18
  31. package/dist_ts/forwarding/config/index.d.ts +4 -2
  32. package/dist_ts/forwarding/config/index.js +5 -3
  33. package/dist_ts/forwarding/handlers/base-handler.js +3 -1
  34. package/dist_ts/forwarding/index.d.ts +5 -6
  35. package/dist_ts/forwarding/index.js +3 -3
  36. package/dist_ts/http/models/http-types.js +1 -1
  37. package/dist_ts/http/port80/acme-interfaces.d.ts +30 -0
  38. package/dist_ts/http/port80/acme-interfaces.js +46 -1
  39. package/dist_ts/http/port80/port80-handler.d.ts +17 -2
  40. package/dist_ts/http/port80/port80-handler.js +49 -11
  41. package/dist_ts/http/router/index.d.ts +5 -1
  42. package/dist_ts/http/router/index.js +4 -2
  43. package/dist_ts/http/router/route-router.d.ts +108 -0
  44. package/dist_ts/http/router/route-router.js +393 -0
  45. package/dist_ts/index.d.ts +8 -2
  46. package/dist_ts/index.js +10 -3
  47. package/dist_ts/proxies/index.d.ts +7 -2
  48. package/dist_ts/proxies/index.js +10 -4
  49. package/dist_ts/proxies/network-proxy/certificate-manager.d.ts +21 -0
  50. package/dist_ts/proxies/network-proxy/certificate-manager.js +92 -1
  51. package/dist_ts/proxies/network-proxy/context-creator.d.ts +34 -0
  52. package/dist_ts/proxies/network-proxy/context-creator.js +108 -0
  53. package/dist_ts/proxies/network-proxy/function-cache.d.ts +90 -0
  54. package/dist_ts/proxies/network-proxy/function-cache.js +198 -0
  55. package/dist_ts/proxies/network-proxy/http-request-handler.d.ts +40 -0
  56. package/dist_ts/proxies/network-proxy/http-request-handler.js +256 -0
  57. package/dist_ts/proxies/network-proxy/http2-request-handler.d.ts +24 -0
  58. package/dist_ts/proxies/network-proxy/http2-request-handler.js +201 -0
  59. package/dist_ts/proxies/network-proxy/models/types.d.ts +73 -1
  60. package/dist_ts/proxies/network-proxy/models/types.js +242 -1
  61. package/dist_ts/proxies/network-proxy/network-proxy.d.ts +23 -20
  62. package/dist_ts/proxies/network-proxy/network-proxy.js +147 -60
  63. package/dist_ts/proxies/network-proxy/request-handler.d.ts +38 -5
  64. package/dist_ts/proxies/network-proxy/request-handler.js +584 -198
  65. package/dist_ts/proxies/network-proxy/security-manager.d.ts +65 -0
  66. package/dist_ts/proxies/network-proxy/security-manager.js +255 -0
  67. package/dist_ts/proxies/network-proxy/websocket-handler.d.ts +13 -2
  68. package/dist_ts/proxies/network-proxy/websocket-handler.js +238 -20
  69. package/dist_ts/proxies/smart-proxy/index.d.ts +1 -1
  70. package/dist_ts/proxies/smart-proxy/index.js +3 -3
  71. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -66
  72. package/dist_ts/proxies/smart-proxy/models/interfaces.js +5 -4
  73. package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +173 -6
  74. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +20 -7
  75. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +49 -108
  76. package/dist_ts/proxies/smart-proxy/port-manager.d.ts +81 -0
  77. package/dist_ts/proxies/smart-proxy/port-manager.js +166 -0
  78. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +7 -5
  79. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +155 -160
  80. package/dist_ts/proxies/smart-proxy/route-helpers/index.d.ts +9 -0
  81. package/dist_ts/proxies/smart-proxy/route-helpers/index.js +11 -0
  82. package/dist_ts/proxies/smart-proxy/route-helpers.d.ts +5 -125
  83. package/dist_ts/proxies/smart-proxy/route-helpers.js +8 -195
  84. package/dist_ts/proxies/smart-proxy/route-manager.d.ts +14 -11
  85. package/dist_ts/proxies/smart-proxy/route-manager.js +81 -124
  86. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +101 -12
  87. package/dist_ts/proxies/smart-proxy/smart-proxy.js +178 -306
  88. package/dist_ts/proxies/smart-proxy/timeout-manager.js +3 -3
  89. package/dist_ts/proxies/smart-proxy/utils/index.d.ts +12 -0
  90. package/dist_ts/proxies/smart-proxy/utils/index.js +19 -0
  91. package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +240 -0
  92. package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +451 -0
  93. package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.d.ts +51 -0
  94. package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.js +124 -0
  95. package/dist_ts/proxies/smart-proxy/utils/route-patterns.d.ts +131 -0
  96. package/dist_ts/proxies/smart-proxy/utils/route-patterns.js +217 -0
  97. package/dist_ts/proxies/smart-proxy/utils/route-utils.d.ts +79 -0
  98. package/dist_ts/proxies/smart-proxy/utils/route-utils.js +266 -0
  99. package/dist_ts/proxies/smart-proxy/utils/route-validators.d.ts +73 -0
  100. package/dist_ts/proxies/smart-proxy/utils/route-validators.js +264 -0
  101. package/package.json +1 -1
  102. package/readme.md +241 -125
  103. package/readme.plan.md +73 -286
  104. package/ts/00_commitinfo_data.ts +1 -1
  105. package/ts/certificate/index.ts +17 -9
  106. package/ts/certificate/models/certificate-types.ts +37 -16
  107. package/ts/certificate/providers/cert-provisioner.ts +247 -54
  108. package/ts/core/models/index.ts +2 -0
  109. package/ts/core/models/route-context.ts +113 -0
  110. package/ts/core/models/socket-augmentation.ts +33 -0
  111. package/ts/core/utils/event-system.ts +376 -0
  112. package/ts/core/utils/index.ts +7 -0
  113. package/ts/core/utils/route-manager.ts +489 -0
  114. package/ts/core/utils/route-utils.ts +312 -0
  115. package/ts/core/utils/security-utils.ts +309 -0
  116. package/ts/core/utils/shared-security-manager.ts +333 -0
  117. package/ts/core/utils/template-utils.ts +124 -0
  118. package/ts/core/utils/websocket-utils.ts +81 -0
  119. package/ts/forwarding/config/forwarding-types.ts +79 -107
  120. package/ts/forwarding/config/index.ts +4 -2
  121. package/ts/forwarding/handlers/base-handler.ts +4 -2
  122. package/ts/forwarding/index.ts +3 -2
  123. package/ts/http/models/http-types.ts +0 -1
  124. package/ts/http/port80/acme-interfaces.ts +84 -0
  125. package/ts/http/port80/port80-handler.ts +61 -15
  126. package/ts/http/router/index.ts +8 -1
  127. package/ts/http/router/route-router.ts +482 -0
  128. package/ts/index.ts +14 -2
  129. package/ts/proxies/index.ts +12 -3
  130. package/ts/proxies/network-proxy/certificate-manager.ts +114 -10
  131. package/ts/proxies/network-proxy/context-creator.ts +145 -0
  132. package/ts/proxies/network-proxy/function-cache.ts +259 -0
  133. package/ts/proxies/network-proxy/http-request-handler.ts +330 -0
  134. package/ts/proxies/network-proxy/http2-request-handler.ts +255 -0
  135. package/ts/proxies/network-proxy/models/types.ts +312 -1
  136. package/ts/proxies/network-proxy/network-proxy.ts +195 -86
  137. package/ts/proxies/network-proxy/request-handler.ts +698 -246
  138. package/ts/proxies/network-proxy/security-manager.ts +298 -0
  139. package/ts/proxies/network-proxy/websocket-handler.ts +276 -33
  140. package/ts/proxies/smart-proxy/index.ts +2 -12
  141. package/ts/proxies/smart-proxy/models/interfaces.ts +13 -67
  142. package/ts/proxies/smart-proxy/models/route-types.ts +223 -25
  143. package/ts/proxies/smart-proxy/network-proxy-bridge.ts +57 -123
  144. package/ts/proxies/smart-proxy/port-manager.ts +195 -0
  145. package/ts/proxies/smart-proxy/route-connection-handler.ts +191 -225
  146. package/ts/proxies/smart-proxy/route-manager.ts +101 -144
  147. package/ts/proxies/smart-proxy/smart-proxy.ts +206 -377
  148. package/ts/proxies/smart-proxy/timeout-manager.ts +2 -2
  149. package/ts/proxies/smart-proxy/utils/index.ts +40 -0
  150. package/ts/proxies/smart-proxy/utils/route-helpers.ts +621 -0
  151. package/ts/proxies/smart-proxy/utils/route-migration-utils.ts +165 -0
  152. package/ts/proxies/smart-proxy/utils/route-patterns.ts +309 -0
  153. package/ts/proxies/smart-proxy/utils/route-utils.ts +330 -0
  154. package/ts/proxies/smart-proxy/utils/route-validators.ts +288 -0
  155. package/ts/forwarding/config/domain-config.ts +0 -28
  156. package/ts/forwarding/config/domain-manager.ts +0 -283
  157. package/ts/proxies/smart-proxy/connection-handler.ts +0 -1240
  158. package/ts/proxies/smart-proxy/domain-config-manager.ts +0 -441
  159. package/ts/proxies/smart-proxy/port-range-manager.ts +0 -211
  160. package/ts/proxies/smart-proxy/route-helpers.ts +0 -344
package/readme.md CHANGED
@@ -7,6 +7,7 @@ A unified high-performance proxy toolkit for Node.js, with **SmartProxy** as the
7
7
  - **Flexible Matching Patterns**: Route by port, domain, path, client IP, and TLS version
8
8
  - **Advanced SNI Handling**: Smart TCP/SNI-based forwarding with IP filtering
9
9
  - **Multiple Action Types**: Forward (with TLS modes), redirect, or block traffic
10
+ - **Dynamic Port Management**: Add or remove listening ports at runtime without restart
10
11
  - **Security Features**: IP allowlists, connection limits, timeouts, and more
11
12
 
12
13
  ## Project Architecture Overview
@@ -105,63 +106,86 @@ Install via npm:
105
106
  npm install @push.rocks/smartproxy
106
107
  ```
107
108
 
108
- ## Quick Start with SmartProxy v14.0.0
109
+ ## Quick Start with SmartProxy
109
110
 
110
- SmartProxy v14.0.0 introduces a new unified route-based configuration system that makes configuring proxies more flexible and intuitive.
111
+ SmartProxy v16.0.0 continues the evolution of the unified route-based configuration system making your proxy setup more flexible and intuitive with improved helper functions.
111
112
 
112
113
  ```typescript
113
- import {
114
- SmartProxy,
115
- createHttpRoute,
116
- createHttpsRoute,
117
- createPassthroughRoute,
118
- createHttpToHttpsRedirect
114
+ import {
115
+ SmartProxy,
116
+ createHttpRoute,
117
+ createHttpsTerminateRoute,
118
+ createHttpsPassthroughRoute,
119
+ createHttpToHttpsRedirect,
120
+ createCompleteHttpsServer,
121
+ createLoadBalancerRoute,
122
+ createStaticFileRoute,
123
+ createApiRoute,
124
+ createWebSocketRoute,
125
+ createSecurityConfig
119
126
  } from '@push.rocks/smartproxy';
120
127
 
121
128
  // Create a new SmartProxy instance with route-based configuration
122
129
  const proxy = new SmartProxy({
123
- // Define all your routing rules in one array
130
+ // Define all your routing rules in a single array
124
131
  routes: [
125
132
  // Basic HTTP route - forward traffic from port 80 to internal service
126
- createHttpRoute({
127
- ports: 80,
128
- domains: 'api.example.com',
129
- target: { host: 'localhost', port: 3000 }
130
- }),
133
+ createHttpRoute('api.example.com', { host: 'localhost', port: 3000 }),
131
134
 
132
135
  // HTTPS route with TLS termination and automatic certificates
133
- createHttpsRoute({
134
- ports: 443,
135
- domains: 'secure.example.com',
136
- target: { host: 'localhost', port: 8080 },
136
+ createHttpsTerminateRoute('secure.example.com', { host: 'localhost', port: 8080 }, {
137
137
  certificate: 'auto' // Use Let's Encrypt
138
138
  }),
139
139
 
140
140
  // HTTPS passthrough for legacy systems
141
- createPassthroughRoute({
142
- ports: 443,
143
- domains: 'legacy.example.com',
144
- target: { host: '192.168.1.10', port: 443 }
141
+ createHttpsPassthroughRoute('legacy.example.com', { host: '192.168.1.10', port: 443 }),
142
+
143
+ // Redirect HTTP to HTTPS for all domains and subdomains
144
+ createHttpToHttpsRedirect(['example.com', '*.example.com']),
145
+
146
+ // Complete HTTPS server (creates both HTTPS route and HTTP redirect)
147
+ ...createCompleteHttpsServer('complete.example.com', { host: 'localhost', port: 3000 }, {
148
+ certificate: 'auto'
145
149
  }),
146
150
 
147
- // Redirect HTTP to HTTPS
148
- createHttpToHttpsRedirect({
149
- domains: ['example.com', '*.example.com']
151
+ // API route with CORS headers
152
+ createApiRoute('api.service.com', '/v1', { host: 'api-backend', port: 8081 }, {
153
+ useTls: true,
154
+ certificate: 'auto',
155
+ addCorsHeaders: true
150
156
  }),
151
157
 
152
- // Complex load balancer setup with security controls
153
- createLoadBalancerRoute({
154
- domains: ['app.example.com'],
155
- targets: ['192.168.1.10', '192.168.1.11', '192.168.1.12'],
156
- targetPort: 8080,
157
- tlsMode: 'terminate',
158
+ // WebSocket route for real-time communication
159
+ createWebSocketRoute('ws.example.com', '/socket', { host: 'socket-server', port: 8082 }, {
160
+ useTls: true,
158
161
  certificate: 'auto',
159
- security: {
160
- allowedIps: ['10.0.0.*', '192.168.1.*'],
161
- blockedIps: ['1.2.3.4'],
162
- maxConnections: 1000
162
+ pingInterval: 30000
163
+ }),
164
+
165
+ // Static file server for web assets
166
+ createStaticFileRoute('static.example.com', '/var/www/html', {
167
+ serveOnHttps: true,
168
+ certificate: 'auto',
169
+ indexFiles: ['index.html', 'index.htm', 'default.html']
170
+ }),
171
+
172
+ // Load balancer with multiple backend servers
173
+ createLoadBalancerRoute(
174
+ 'app.example.com',
175
+ ['192.168.1.10', '192.168.1.11', '192.168.1.12'],
176
+ 8080,
177
+ {
178
+ tls: {
179
+ mode: 'terminate',
180
+ certificate: 'auto'
181
+ },
182
+ security: createSecurityConfig({
183
+ allowedIps: ['10.0.0.*', '192.168.1.*'],
184
+ blockedIps: ['1.2.3.4'],
185
+ maxConnections: 1000
186
+ })
163
187
  }
164
- })
188
+ )
165
189
  ],
166
190
 
167
191
  // Global settings that apply to all routes
@@ -188,14 +212,18 @@ proxy.on('certificate', evt => {
188
212
  await proxy.start();
189
213
 
190
214
  // Dynamically add new routes later
191
- await proxy.addRoutes([
192
- createHttpsRoute({
193
- domains: 'new-domain.com',
194
- target: { host: 'localhost', port: 9000 },
215
+ await proxy.updateRoutes([
216
+ ...proxy.settings.routes,
217
+ createHttpsTerminateRoute('new-domain.com', { host: 'localhost', port: 9000 }, {
195
218
  certificate: 'auto'
196
219
  })
197
220
  ]);
198
221
 
222
+ // Dynamically add or remove port listeners
223
+ await proxy.addListeningPort(8081);
224
+ await proxy.removeListeningPort(8081);
225
+ console.log('Currently listening on ports:', proxy.getListeningPorts());
226
+
199
227
  // Later, gracefully shut down
200
228
  await proxy.stop();
201
229
  ```
@@ -445,33 +473,33 @@ const route = {
445
473
  name: 'Web Server'
446
474
  };
447
475
 
448
- // Use the helper function:
449
- const route = createHttpRoute({
450
- domains: 'example.com',
451
- target: { host: 'localhost', port: 8080 },
476
+ // Use the helper function for cleaner syntax:
477
+ const route = createHttpRoute('example.com', { host: 'localhost', port: 8080 }, {
452
478
  name: 'Web Server'
453
479
  });
454
480
  ```
455
481
 
456
482
  Available helper functions:
457
- - `createRoute()` - Basic function to create any route configuration
458
483
  - `createHttpRoute()` - Create an HTTP forwarding route
459
- - `createHttpsRoute()` - Create an HTTPS route with TLS termination
460
- - `createPassthroughRoute()` - Create an HTTPS passthrough route
461
- - `createRedirectRoute()` - Create a generic redirect route
484
+ - `createHttpsTerminateRoute()` - Create an HTTPS route with TLS termination
485
+ - `createHttpsPassthroughRoute()` - Create an HTTPS passthrough route
462
486
  - `createHttpToHttpsRedirect()` - Create an HTTP to HTTPS redirect
487
+ - `createCompleteHttpsServer()` - Create a complete HTTPS server setup with HTTP redirect
488
+ - `createLoadBalancerRoute()` - Create a route for load balancing across multiple backends
489
+ - `createStaticFileRoute()` - Create a route for serving static files
490
+ - `createApiRoute()` - Create an API route with path matching and CORS support
491
+ - `createWebSocketRoute()` - Create a route for WebSocket connections
492
+ - `createPortRange()` - Helper to create port range configurations
493
+ - `createSecurityConfig()` - Helper to create security configuration objects
463
494
  - `createBlockRoute()` - Create a route to block specific traffic
464
- - `createLoadBalancerRoute()` - Create a route for load balancing
465
- - `createHttpsServer()` - Create a complete HTTPS server setup with HTTP redirect
495
+ - `createTestRoute()` - Create a test route for debugging and testing
466
496
 
467
497
  ## What You Can Do with SmartProxy
468
498
 
469
499
  1. **Route-Based Traffic Management**
470
500
  ```typescript
471
501
  // Route requests for different domains to different backend servers
472
- createHttpsRoute({
473
- domains: 'api.example.com',
474
- target: { host: 'api-server', port: 3000 },
502
+ createHttpsTerminateRoute('api.example.com', { host: 'api-server', port: 3000 }, {
475
503
  certificate: 'auto'
476
504
  })
477
505
  ```
@@ -479,9 +507,7 @@ Available helper functions:
479
507
  2. **Automatic SSL with Let's Encrypt**
480
508
  ```typescript
481
509
  // Get and automatically renew certificates
482
- createHttpsRoute({
483
- domains: 'secure.example.com',
484
- target: { host: 'localhost', port: 8080 },
510
+ createHttpsTerminateRoute('secure.example.com', { host: 'localhost', port: 8080 }, {
485
511
  certificate: 'auto'
486
512
  })
487
513
  ```
@@ -489,21 +515,23 @@ Available helper functions:
489
515
  3. **Load Balancing**
490
516
  ```typescript
491
517
  // Distribute traffic across multiple backend servers
492
- createLoadBalancerRoute({
493
- domains: 'app.example.com',
494
- targets: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
495
- targetPort: 8080,
496
- tlsMode: 'terminate',
497
- certificate: 'auto'
498
- })
518
+ createLoadBalancerRoute(
519
+ 'app.example.com',
520
+ ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
521
+ 8080,
522
+ {
523
+ tls: {
524
+ mode: 'terminate',
525
+ certificate: 'auto'
526
+ }
527
+ }
528
+ )
499
529
  ```
500
530
 
501
531
  4. **Security Controls**
502
532
  ```typescript
503
533
  // Restrict access based on IP addresses
504
- createHttpsRoute({
505
- domains: 'admin.example.com',
506
- target: { host: 'localhost', port: 8080 },
534
+ createHttpsTerminateRoute('admin.example.com', { host: 'localhost', port: 8080 }, {
507
535
  certificate: 'auto',
508
536
  security: {
509
537
  allowedIps: ['10.0.0.*', '192.168.1.*'],
@@ -515,19 +543,14 @@ Available helper functions:
515
543
  5. **Wildcard Domains**
516
544
  ```typescript
517
545
  // Handle all subdomains with one config
518
- createPassthroughRoute({
519
- domains: ['example.com', '*.example.com'],
520
- target: { host: 'backend-server', port: 443 }
521
- })
546
+ createHttpsPassthroughRoute(['example.com', '*.example.com'], { host: 'backend-server', port: 443 })
522
547
  ```
523
548
 
524
549
  6. **Path-Based Routing**
525
550
  ```typescript
526
551
  // Route based on URL path
527
- createHttpsRoute({
528
- domains: 'example.com',
529
- path: '/api/*',
530
- target: { host: 'api-server', port: 3000 },
552
+ createApiRoute('example.com', '/api', { host: 'api-server', port: 3000 }, {
553
+ useTls: true,
531
554
  certificate: 'auto'
532
555
  })
533
556
  ```
@@ -535,19 +558,43 @@ Available helper functions:
535
558
  7. **Block Malicious Traffic**
536
559
  ```typescript
537
560
  // Block traffic from specific IPs
538
- createBlockRoute({
539
- ports: [80, 443],
561
+ createBlockRoute([80, 443], {
540
562
  clientIp: ['1.2.3.*', '5.6.7.*'],
541
563
  priority: 1000 // High priority to ensure blocking
542
564
  })
543
565
  ```
544
566
 
567
+ 8. **Dynamic Port Management**
568
+ ```typescript
569
+ // Start the proxy with initial configuration
570
+ const proxy = new SmartProxy({
571
+ routes: [
572
+ createHttpRoute('example.com', { host: 'localhost', port: 8080 })
573
+ ]
574
+ });
575
+ await proxy.start();
576
+
577
+ // Dynamically add a new port listener
578
+ await proxy.addListeningPort(8081);
579
+
580
+ // Add a route for the new port
581
+ const currentRoutes = proxy.settings.routes;
582
+ const newRoute = createHttpRoute('api.example.com', { host: 'api-server', port: 3000 });
583
+ newRoute.match.ports = 8081; // Override the default port
584
+
585
+ // Update routes - will automatically sync port listeners
586
+ await proxy.updateRoutes([...currentRoutes, newRoute]);
587
+
588
+ // Later, remove a port listener when needed
589
+ await proxy.removeListeningPort(8081);
590
+ ```
591
+
545
592
  ## Other Components
546
593
 
547
594
  While SmartProxy provides a unified API for most needs, you can also use individual components:
548
595
 
549
596
  ### NetworkProxy
550
- For HTTP/HTTPS reverse proxy with TLS termination and WebSocket support:
597
+ For HTTP/HTTPS reverse proxy with TLS termination and WebSocket support. Now with native route-based configuration support:
551
598
 
552
599
  ```typescript
553
600
  import { NetworkProxy } from '@push.rocks/smartproxy';
@@ -555,9 +602,49 @@ import * as fs from 'fs';
555
602
 
556
603
  const proxy = new NetworkProxy({ port: 443 });
557
604
  await proxy.start();
605
+
606
+ // Modern route-based configuration (recommended)
607
+ await proxy.updateRouteConfigs([
608
+ {
609
+ match: {
610
+ ports: 443,
611
+ domains: 'example.com'
612
+ },
613
+ action: {
614
+ type: 'forward',
615
+ target: {
616
+ host: '127.0.0.1',
617
+ port: 3000
618
+ },
619
+ tls: {
620
+ mode: 'terminate',
621
+ certificate: {
622
+ cert: fs.readFileSync('cert.pem', 'utf8'),
623
+ key: fs.readFileSync('key.pem', 'utf8')
624
+ }
625
+ },
626
+ advanced: {
627
+ headers: {
628
+ 'X-Forwarded-By': 'NetworkProxy'
629
+ },
630
+ urlRewrite: {
631
+ pattern: '^/old/(.*)$',
632
+ target: '/new/$1',
633
+ flags: 'g'
634
+ }
635
+ },
636
+ websocket: {
637
+ enabled: true,
638
+ pingInterval: 30000
639
+ }
640
+ }
641
+ }
642
+ ]);
643
+
644
+ // Legacy configuration (for backward compatibility)
558
645
  await proxy.updateProxyConfigs([
559
646
  {
560
- hostName: 'example.com',
647
+ hostName: 'legacy.example.com',
561
648
  destinationIps: ['127.0.0.1'],
562
649
  destinationPorts: [3000],
563
650
  publicKey: fs.readFileSync('cert.pem', 'utf8'),
@@ -607,19 +694,20 @@ const redirect = new SslRedirect(80);
607
694
  await redirect.start();
608
695
  ```
609
696
 
610
- ## Migration from v13.x to v14.0.0
697
+ ## Migration to v16.0.0
611
698
 
612
- Version 14.0.0 introduces a breaking change with the new route-based configuration system:
699
+ Version 16.0.0 completes the migration to a fully unified route-based configuration system with improved helper functions:
613
700
 
614
701
  ### Key Changes
615
702
 
616
- 1. **Configuration Structure**: The configuration now uses the match/action pattern instead of the old domain-based and port-based approach
617
- 2. **SmartProxy Options**: Now takes an array of route configurations instead of `domainConfigs` and port ranges
618
- 3. **Helper Functions**: New helper functions have been introduced to simplify configuration
703
+ 1. **Pure Route-Based API**: The configuration now exclusively uses the match/action pattern with no legacy interfaces
704
+ 2. **Improved Helper Functions**: Enhanced helper functions with cleaner parameter signatures
705
+ 3. **Removed Legacy Support**: Legacy domain-based APIs have been completely removed
706
+ 4. **More Route Pattern Helpers**: Additional helper functions for common routing patterns
619
707
 
620
708
  ### Migration Example
621
709
 
622
- **v13.x Configuration**:
710
+ **Legacy Configuration (pre-v14)**:
623
711
  ```typescript
624
712
  import { SmartProxy, createDomainConfig, httpOnly, tlsTerminateToHttp } from '@push.rocks/smartproxy';
625
713
 
@@ -635,29 +723,48 @@ const proxy = new SmartProxy({
635
723
  });
636
724
  ```
637
725
 
638
- **v14.0.0 Configuration**:
726
+ **Current Configuration (v16.0.0)**:
639
727
  ```typescript
640
- import { SmartProxy, createHttpsRoute } from '@push.rocks/smartproxy';
728
+ import { SmartProxy, createHttpsTerminateRoute } from '@push.rocks/smartproxy';
641
729
 
642
730
  const proxy = new SmartProxy({
643
731
  routes: [
644
- createHttpsRoute({
645
- ports: 443,
646
- domains: 'example.com',
647
- target: { host: 'localhost', port: 8080 },
732
+ createHttpsTerminateRoute('example.com', { host: 'localhost', port: 8080 }, {
648
733
  certificate: 'auto'
649
734
  })
650
- ]
735
+ ],
736
+ acme: {
737
+ enabled: true,
738
+ useProduction: true
739
+ }
651
740
  });
652
741
  ```
653
742
 
654
- ### Migration Steps
743
+ ### Migration from v14.x/v15.x to v16.0.0
744
+
745
+ If you're already using route-based configuration, update your helper function calls:
746
+
747
+ ```typescript
748
+ // Old v14.x/v15.x style:
749
+ createHttpsRoute({
750
+ domains: 'example.com',
751
+ target: { host: 'localhost', port: 8080 },
752
+ certificate: 'auto'
753
+ })
754
+
755
+ // New v16.0.0 style:
756
+ createHttpsTerminateRoute('example.com', { host: 'localhost', port: 8080 }, {
757
+ certificate: 'auto'
758
+ })
759
+ ```
760
+
761
+ ### Complete Migration Steps
655
762
 
656
- 1. Replace `domainConfigs` with an array of route configurations using `routes`
657
- 2. Convert each domain configuration to use the new helper functions
658
- 3. Update any code that uses `updateDomainConfigs()` to use `addRoutes()` or `updateRoutes()`
659
- 4. For port-only configurations, create route configurations with port matching only
660
- 5. For SNI-based routing, SNI is now automatically enabled when needed
763
+ 1. Replace any remaining `domainConfigs` with route-based configuration using the `routes` array
764
+ 2. Update helper function calls to use the newer parameter format (domain first, target second, options third)
765
+ 3. Use the new specific helper functions (e.g., `createHttpsTerminateRoute` instead of `createHttpsRoute`)
766
+ 4. Update any code that uses `updateDomainConfigs()` to use `addRoutes()` or `updateRoutes()`
767
+ 5. For port-only configurations, create route configurations with port matching only
661
768
 
662
769
  ## Architecture & Flow Diagrams
663
770
 
@@ -806,33 +913,26 @@ The SmartProxy component with route-based configuration offers a clean, unified
806
913
  Create a flexible API gateway to route traffic to different microservices based on domain and path:
807
914
 
808
915
  ```typescript
809
- import { SmartProxy, createHttpsRoute } from '@push.rocks/smartproxy';
916
+ import { SmartProxy, createApiRoute, createHttpsTerminateRoute } from '@push.rocks/smartproxy';
810
917
 
811
918
  const apiGateway = new SmartProxy({
812
919
  routes: [
813
920
  // Users API
814
- createHttpsRoute({
815
- ports: 443,
816
- domains: 'api.example.com',
817
- path: '/users/*',
818
- target: { host: 'users-service', port: 3000 },
819
- certificate: 'auto'
921
+ createApiRoute('api.example.com', '/users', { host: 'users-service', port: 3000 }, {
922
+ useTls: true,
923
+ certificate: 'auto',
924
+ addCorsHeaders: true
820
925
  }),
821
926
 
822
927
  // Products API
823
- createHttpsRoute({
824
- ports: 443,
825
- domains: 'api.example.com',
826
- path: '/products/*',
827
- target: { host: 'products-service', port: 3001 },
828
- certificate: 'auto'
928
+ createApiRoute('api.example.com', '/products', { host: 'products-service', port: 3001 }, {
929
+ useTls: true,
930
+ certificate: 'auto',
931
+ addCorsHeaders: true
829
932
  }),
830
933
 
831
934
  // Admin dashboard with extra security
832
- createHttpsRoute({
833
- ports: 443,
834
- domains: 'admin.example.com',
835
- target: { host: 'admin-dashboard', port: 8080 },
935
+ createHttpsTerminateRoute('admin.example.com', { host: 'admin-dashboard', port: 8080 }, {
836
936
  certificate: 'auto',
837
937
  security: {
838
938
  allowedIps: ['10.0.0.*', '192.168.1.*'] // Only allow internal network
@@ -1056,18 +1156,34 @@ createRedirectRoute({
1056
1156
  - Socket opts: `noDelay`, `keepAlive`, `enableKeepAliveProbes`
1057
1157
  - `certProvisionFunction` (callback) - Custom certificate provisioning
1058
1158
 
1159
+ #### SmartProxy Dynamic Port Management Methods
1160
+ - `async addListeningPort(port: number)` - Add a new port listener without changing routes
1161
+ - `async removeListeningPort(port: number)` - Remove a port listener without changing routes
1162
+ - `getListeningPorts()` - Get all ports currently being listened on
1163
+ - `async updateRoutes(routes: IRouteConfig[])` - Update routes and automatically adjust port listeners
1164
+
1059
1165
  ### NetworkProxy (INetworkProxyOptions)
1060
- - `port` (number, required)
1061
- - `backendProtocol` ('http1'|'http2', default 'http1')
1062
- - `maxConnections` (number, default 10000)
1063
- - `keepAliveTimeout` (ms, default 120000)
1064
- - `headersTimeout` (ms, default 60000)
1065
- - `cors` (object)
1066
- - `connectionPoolSize` (number, default 50)
1067
- - `logLevel` ('error'|'warn'|'info'|'debug')
1068
- - `acme` (IAcmeOptions)
1069
- - `useExternalPort80Handler` (boolean)
1070
- - `portProxyIntegration` (boolean)
1166
+ - `port` (number, required) - Main port to listen on
1167
+ - `backendProtocol` ('http1'|'http2', default 'http1') - Protocol to use with backend servers
1168
+ - `maxConnections` (number, default 10000) - Maximum concurrent connections
1169
+ - `keepAliveTimeout` (ms, default 120000) - Connection keep-alive timeout
1170
+ - `headersTimeout` (ms, default 60000) - Timeout for receiving complete headers
1171
+ - `cors` (object) - Cross-Origin Resource Sharing configuration
1172
+ - `connectionPoolSize` (number, default 50) - Size of the connection pool for backend servers
1173
+ - `logLevel` ('error'|'warn'|'info'|'debug') - Logging verbosity level
1174
+ - `acme` (IAcmeOptions) - ACME certificate configuration
1175
+ - `useExternalPort80Handler` (boolean) - Use external port 80 handler for ACME challenges
1176
+ - `portProxyIntegration` (boolean) - Integration with other proxies
1177
+
1178
+ #### NetworkProxy Enhanced Features
1179
+ NetworkProxy now supports full route-based configuration including:
1180
+ - Advanced request and response header manipulation
1181
+ - URL rewriting with RegExp pattern matching
1182
+ - Template variable resolution for dynamic values (e.g. `{domain}`, `{clientIp}`)
1183
+ - Function-based dynamic target resolution
1184
+ - Security features (IP filtering, rate limiting, authentication)
1185
+ - WebSocket configuration with path rewriting, custom headers, ping control, and size limits
1186
+ - Context-aware CORS configuration
1071
1187
 
1072
1188
  ### Port80Handler (IAcmeOptions)
1073
1189
  - `enabled` (boolean, default true)