@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.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/certificate/index.d.ts +10 -4
- package/dist_ts/certificate/index.js +5 -7
- package/dist_ts/certificate/models/certificate-types.d.ts +35 -15
- package/dist_ts/certificate/providers/cert-provisioner.d.ts +41 -15
- package/dist_ts/certificate/providers/cert-provisioner.js +201 -41
- package/dist_ts/core/models/index.d.ts +2 -0
- package/dist_ts/core/models/index.js +3 -1
- package/dist_ts/core/models/route-context.d.ts +62 -0
- package/dist_ts/core/models/route-context.js +43 -0
- package/dist_ts/core/models/socket-augmentation.d.ts +12 -0
- package/dist_ts/core/models/socket-augmentation.js +18 -0
- package/dist_ts/core/utils/event-system.d.ts +200 -0
- package/dist_ts/core/utils/event-system.js +224 -0
- package/dist_ts/core/utils/index.d.ts +7 -0
- package/dist_ts/core/utils/index.js +8 -1
- package/dist_ts/core/utils/route-manager.d.ts +118 -0
- package/dist_ts/core/utils/route-manager.js +383 -0
- package/dist_ts/core/utils/route-utils.d.ts +94 -0
- package/dist_ts/core/utils/route-utils.js +264 -0
- package/dist_ts/core/utils/security-utils.d.ts +111 -0
- package/dist_ts/core/utils/security-utils.js +212 -0
- package/dist_ts/core/utils/shared-security-manager.d.ts +110 -0
- package/dist_ts/core/utils/shared-security-manager.js +252 -0
- package/dist_ts/core/utils/template-utils.d.ts +37 -0
- package/dist_ts/core/utils/template-utils.js +104 -0
- package/dist_ts/core/utils/websocket-utils.d.ts +23 -0
- package/dist_ts/core/utils/websocket-utils.js +86 -0
- package/dist_ts/forwarding/config/forwarding-types.d.ts +40 -76
- package/dist_ts/forwarding/config/forwarding-types.js +19 -18
- package/dist_ts/forwarding/config/index.d.ts +4 -2
- package/dist_ts/forwarding/config/index.js +5 -3
- package/dist_ts/forwarding/handlers/base-handler.js +3 -1
- package/dist_ts/forwarding/index.d.ts +5 -6
- package/dist_ts/forwarding/index.js +3 -3
- package/dist_ts/http/models/http-types.js +1 -1
- package/dist_ts/http/port80/acme-interfaces.d.ts +30 -0
- package/dist_ts/http/port80/acme-interfaces.js +46 -1
- package/dist_ts/http/port80/port80-handler.d.ts +17 -2
- package/dist_ts/http/port80/port80-handler.js +49 -11
- package/dist_ts/http/router/index.d.ts +5 -1
- package/dist_ts/http/router/index.js +4 -2
- package/dist_ts/http/router/route-router.d.ts +108 -0
- package/dist_ts/http/router/route-router.js +393 -0
- package/dist_ts/index.d.ts +8 -2
- package/dist_ts/index.js +10 -3
- package/dist_ts/proxies/index.d.ts +7 -2
- package/dist_ts/proxies/index.js +10 -4
- package/dist_ts/proxies/network-proxy/certificate-manager.d.ts +21 -0
- package/dist_ts/proxies/network-proxy/certificate-manager.js +92 -1
- package/dist_ts/proxies/network-proxy/context-creator.d.ts +34 -0
- package/dist_ts/proxies/network-proxy/context-creator.js +108 -0
- package/dist_ts/proxies/network-proxy/function-cache.d.ts +90 -0
- package/dist_ts/proxies/network-proxy/function-cache.js +198 -0
- package/dist_ts/proxies/network-proxy/http-request-handler.d.ts +40 -0
- package/dist_ts/proxies/network-proxy/http-request-handler.js +256 -0
- package/dist_ts/proxies/network-proxy/http2-request-handler.d.ts +24 -0
- package/dist_ts/proxies/network-proxy/http2-request-handler.js +201 -0
- package/dist_ts/proxies/network-proxy/models/types.d.ts +73 -1
- package/dist_ts/proxies/network-proxy/models/types.js +242 -1
- package/dist_ts/proxies/network-proxy/network-proxy.d.ts +23 -20
- package/dist_ts/proxies/network-proxy/network-proxy.js +147 -60
- package/dist_ts/proxies/network-proxy/request-handler.d.ts +38 -5
- package/dist_ts/proxies/network-proxy/request-handler.js +584 -198
- package/dist_ts/proxies/network-proxy/security-manager.d.ts +65 -0
- package/dist_ts/proxies/network-proxy/security-manager.js +255 -0
- package/dist_ts/proxies/network-proxy/websocket-handler.d.ts +13 -2
- package/dist_ts/proxies/network-proxy/websocket-handler.js +238 -20
- package/dist_ts/proxies/smart-proxy/index.d.ts +1 -1
- package/dist_ts/proxies/smart-proxy/index.js +3 -3
- package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -66
- package/dist_ts/proxies/smart-proxy/models/interfaces.js +5 -4
- package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +173 -6
- package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +20 -7
- package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +49 -108
- package/dist_ts/proxies/smart-proxy/port-manager.d.ts +81 -0
- package/dist_ts/proxies/smart-proxy/port-manager.js +166 -0
- package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +7 -5
- package/dist_ts/proxies/smart-proxy/route-connection-handler.js +155 -160
- package/dist_ts/proxies/smart-proxy/route-helpers/index.d.ts +9 -0
- package/dist_ts/proxies/smart-proxy/route-helpers/index.js +11 -0
- package/dist_ts/proxies/smart-proxy/route-helpers.d.ts +5 -125
- package/dist_ts/proxies/smart-proxy/route-helpers.js +8 -195
- package/dist_ts/proxies/smart-proxy/route-manager.d.ts +14 -11
- package/dist_ts/proxies/smart-proxy/route-manager.js +81 -124
- package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +101 -12
- package/dist_ts/proxies/smart-proxy/smart-proxy.js +178 -306
- package/dist_ts/proxies/smart-proxy/timeout-manager.js +3 -3
- package/dist_ts/proxies/smart-proxy/utils/index.d.ts +12 -0
- package/dist_ts/proxies/smart-proxy/utils/index.js +19 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +240 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +451 -0
- package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.d.ts +51 -0
- package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.js +124 -0
- package/dist_ts/proxies/smart-proxy/utils/route-patterns.d.ts +131 -0
- package/dist_ts/proxies/smart-proxy/utils/route-patterns.js +217 -0
- package/dist_ts/proxies/smart-proxy/utils/route-utils.d.ts +79 -0
- package/dist_ts/proxies/smart-proxy/utils/route-utils.js +266 -0
- package/dist_ts/proxies/smart-proxy/utils/route-validators.d.ts +73 -0
- package/dist_ts/proxies/smart-proxy/utils/route-validators.js +264 -0
- package/package.json +1 -1
- package/readme.md +241 -125
- package/readme.plan.md +73 -286
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/certificate/index.ts +17 -9
- package/ts/certificate/models/certificate-types.ts +37 -16
- package/ts/certificate/providers/cert-provisioner.ts +247 -54
- package/ts/core/models/index.ts +2 -0
- package/ts/core/models/route-context.ts +113 -0
- package/ts/core/models/socket-augmentation.ts +33 -0
- package/ts/core/utils/event-system.ts +376 -0
- package/ts/core/utils/index.ts +7 -0
- package/ts/core/utils/route-manager.ts +489 -0
- package/ts/core/utils/route-utils.ts +312 -0
- package/ts/core/utils/security-utils.ts +309 -0
- package/ts/core/utils/shared-security-manager.ts +333 -0
- package/ts/core/utils/template-utils.ts +124 -0
- package/ts/core/utils/websocket-utils.ts +81 -0
- package/ts/forwarding/config/forwarding-types.ts +79 -107
- package/ts/forwarding/config/index.ts +4 -2
- package/ts/forwarding/handlers/base-handler.ts +4 -2
- package/ts/forwarding/index.ts +3 -2
- package/ts/http/models/http-types.ts +0 -1
- package/ts/http/port80/acme-interfaces.ts +84 -0
- package/ts/http/port80/port80-handler.ts +61 -15
- package/ts/http/router/index.ts +8 -1
- package/ts/http/router/route-router.ts +482 -0
- package/ts/index.ts +14 -2
- package/ts/proxies/index.ts +12 -3
- package/ts/proxies/network-proxy/certificate-manager.ts +114 -10
- package/ts/proxies/network-proxy/context-creator.ts +145 -0
- package/ts/proxies/network-proxy/function-cache.ts +259 -0
- package/ts/proxies/network-proxy/http-request-handler.ts +330 -0
- package/ts/proxies/network-proxy/http2-request-handler.ts +255 -0
- package/ts/proxies/network-proxy/models/types.ts +312 -1
- package/ts/proxies/network-proxy/network-proxy.ts +195 -86
- package/ts/proxies/network-proxy/request-handler.ts +698 -246
- package/ts/proxies/network-proxy/security-manager.ts +298 -0
- package/ts/proxies/network-proxy/websocket-handler.ts +276 -33
- package/ts/proxies/smart-proxy/index.ts +2 -12
- package/ts/proxies/smart-proxy/models/interfaces.ts +13 -67
- package/ts/proxies/smart-proxy/models/route-types.ts +223 -25
- package/ts/proxies/smart-proxy/network-proxy-bridge.ts +57 -123
- package/ts/proxies/smart-proxy/port-manager.ts +195 -0
- package/ts/proxies/smart-proxy/route-connection-handler.ts +191 -225
- package/ts/proxies/smart-proxy/route-manager.ts +101 -144
- package/ts/proxies/smart-proxy/smart-proxy.ts +206 -377
- package/ts/proxies/smart-proxy/timeout-manager.ts +2 -2
- package/ts/proxies/smart-proxy/utils/index.ts +40 -0
- package/ts/proxies/smart-proxy/utils/route-helpers.ts +621 -0
- package/ts/proxies/smart-proxy/utils/route-migration-utils.ts +165 -0
- package/ts/proxies/smart-proxy/utils/route-patterns.ts +309 -0
- package/ts/proxies/smart-proxy/utils/route-utils.ts +330 -0
- package/ts/proxies/smart-proxy/utils/route-validators.ts +288 -0
- package/ts/forwarding/config/domain-config.ts +0 -28
- package/ts/forwarding/config/domain-manager.ts +0 -283
- package/ts/proxies/smart-proxy/connection-handler.ts +0 -1240
- package/ts/proxies/smart-proxy/domain-config-manager.ts +0 -441
- package/ts/proxies/smart-proxy/port-range-manager.ts +0 -211
- package/ts/proxies/smart-proxy/route-helpers.ts +0 -344
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import * as plugins from '../../plugins.js';
|
|
2
2
|
import {
|
|
3
|
-
createLogger
|
|
3
|
+
createLogger,
|
|
4
|
+
RouteManager,
|
|
5
|
+
convertLegacyConfigToRouteConfig
|
|
4
6
|
} from './models/types.js';
|
|
5
7
|
import type {
|
|
6
8
|
INetworkProxyOptions,
|
|
7
9
|
ILogger,
|
|
8
10
|
IReverseProxyConfig
|
|
9
11
|
} from './models/types.js';
|
|
12
|
+
import type { IRouteConfig } from '../smart-proxy/models/route-types.js';
|
|
13
|
+
import type { IRouteContext, IHttpRouteContext } from '../../core/models/route-context.js';
|
|
14
|
+
import { createBaseRouteContext } from '../../core/models/route-context.js';
|
|
10
15
|
import { CertificateManager } from './certificate-manager.js';
|
|
11
16
|
import { ConnectionPool } from './connection-pool.js';
|
|
12
17
|
import { RequestHandler, type IMetricsTracker } from './request-handler.js';
|
|
13
18
|
import { WebSocketHandler } from './websocket-handler.js';
|
|
14
19
|
import { ProxyRouter } from '../../http/router/index.js';
|
|
20
|
+
import { RouteRouter } from '../../http/router/route-router.js';
|
|
15
21
|
import { Port80Handler } from '../../http/port80/port80-handler.js';
|
|
22
|
+
import { FunctionCache } from './function-cache.js';
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
25
|
* NetworkProxy provides a reverse proxy with TLS termination, WebSocket support,
|
|
@@ -25,17 +32,20 @@ export class NetworkProxy implements IMetricsTracker {
|
|
|
25
32
|
}
|
|
26
33
|
// Configuration
|
|
27
34
|
public options: INetworkProxyOptions;
|
|
28
|
-
public
|
|
29
|
-
|
|
35
|
+
public routes: IRouteConfig[] = [];
|
|
36
|
+
|
|
30
37
|
// Server instances (HTTP/2 with HTTP/1 fallback)
|
|
31
38
|
public httpsServer: any;
|
|
32
|
-
|
|
39
|
+
|
|
33
40
|
// Core components
|
|
34
41
|
private certificateManager: CertificateManager;
|
|
35
42
|
private connectionPool: ConnectionPool;
|
|
36
43
|
private requestHandler: RequestHandler;
|
|
37
44
|
private webSocketHandler: WebSocketHandler;
|
|
38
|
-
private
|
|
45
|
+
private legacyRouter = new ProxyRouter(); // Legacy router for backward compatibility
|
|
46
|
+
private router = new RouteRouter(); // New modern router
|
|
47
|
+
private routeManager: RouteManager;
|
|
48
|
+
private functionCache: FunctionCache;
|
|
39
49
|
|
|
40
50
|
// State tracking
|
|
41
51
|
public socketMap = new plugins.lik.ObjectMap<plugins.net.Socket>();
|
|
@@ -94,15 +104,41 @@ export class NetworkProxy implements IMetricsTracker {
|
|
|
94
104
|
|
|
95
105
|
// Initialize logger
|
|
96
106
|
this.logger = createLogger(this.options.logLevel);
|
|
97
|
-
|
|
98
|
-
// Initialize
|
|
107
|
+
|
|
108
|
+
// Initialize route manager
|
|
109
|
+
this.routeManager = new RouteManager(this.logger);
|
|
110
|
+
|
|
111
|
+
// Initialize function cache
|
|
112
|
+
this.functionCache = new FunctionCache(this.logger, {
|
|
113
|
+
maxCacheSize: this.options.functionCacheSize || 1000,
|
|
114
|
+
defaultTtl: this.options.functionCacheTtl || 5000
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Initialize other components
|
|
99
118
|
this.certificateManager = new CertificateManager(this.options);
|
|
100
119
|
this.connectionPool = new ConnectionPool(this.options);
|
|
101
|
-
this.requestHandler = new RequestHandler(
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
this.requestHandler = new RequestHandler(
|
|
121
|
+
this.options,
|
|
122
|
+
this.connectionPool,
|
|
123
|
+
this.legacyRouter, // Still use legacy router for backward compatibility
|
|
124
|
+
this.routeManager,
|
|
125
|
+
this.functionCache,
|
|
126
|
+
this.router // Pass the new modern router as well
|
|
127
|
+
);
|
|
128
|
+
this.webSocketHandler = new WebSocketHandler(
|
|
129
|
+
this.options,
|
|
130
|
+
this.connectionPool,
|
|
131
|
+
this.legacyRouter,
|
|
132
|
+
this.routes // Pass current routes to WebSocketHandler
|
|
133
|
+
);
|
|
134
|
+
|
|
104
135
|
// Connect request handler to this metrics tracker
|
|
105
136
|
this.requestHandler.setMetricsTracker(this);
|
|
137
|
+
|
|
138
|
+
// Initialize with any provided routes
|
|
139
|
+
if (this.options.routes && this.options.routes.length > 0) {
|
|
140
|
+
this.updateRouteConfigs(this.options.routes);
|
|
141
|
+
}
|
|
106
142
|
}
|
|
107
143
|
|
|
108
144
|
/**
|
|
@@ -124,6 +160,14 @@ export class NetworkProxy implements IMetricsTracker {
|
|
|
124
160
|
* Useful for SmartProxy to determine where to forward connections
|
|
125
161
|
*/
|
|
126
162
|
public getListeningPort(): number {
|
|
163
|
+
// If the server is running, get the actual listening port
|
|
164
|
+
if (this.httpsServer && this.httpsServer.address()) {
|
|
165
|
+
const address = this.httpsServer.address();
|
|
166
|
+
if (address && typeof address === 'object' && 'port' in address) {
|
|
167
|
+
return address.port;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Fallback to configured port
|
|
127
171
|
return this.options.port;
|
|
128
172
|
}
|
|
129
173
|
|
|
@@ -171,7 +215,8 @@ export class NetworkProxy implements IMetricsTracker {
|
|
|
171
215
|
connectionPoolSize: this.connectionPool.getPoolStatus(),
|
|
172
216
|
uptime: Math.floor((Date.now() - this.startTime) / 1000),
|
|
173
217
|
memoryUsage: process.memoryUsage(),
|
|
174
|
-
activeWebSockets: this.webSocketHandler.getConnectionInfo().activeConnections
|
|
218
|
+
activeWebSockets: this.webSocketHandler.getConnectionInfo().activeConnections,
|
|
219
|
+
functionCache: this.functionCache.getStats()
|
|
175
220
|
};
|
|
176
221
|
}
|
|
177
222
|
|
|
@@ -325,96 +370,139 @@ export class NetworkProxy implements IMetricsTracker {
|
|
|
325
370
|
}
|
|
326
371
|
|
|
327
372
|
/**
|
|
328
|
-
* Updates
|
|
373
|
+
* Updates the route configurations - this is the primary method for configuring NetworkProxy
|
|
374
|
+
* @param routes The new route configurations to use
|
|
329
375
|
*/
|
|
330
|
-
public async
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
this.
|
|
337
|
-
this.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
376
|
+
public async updateRouteConfigs(routes: IRouteConfig[]): Promise<void> {
|
|
377
|
+
this.logger.info(`Updating route configurations (${routes.length} routes)`);
|
|
378
|
+
|
|
379
|
+
// Update routes in RouteManager, modern router, WebSocketHandler, and SecurityManager
|
|
380
|
+
this.routeManager.updateRoutes(routes);
|
|
381
|
+
this.router.setRoutes(routes);
|
|
382
|
+
this.webSocketHandler.setRoutes(routes);
|
|
383
|
+
this.requestHandler.securityManager.setRoutes(routes);
|
|
384
|
+
this.routes = routes;
|
|
385
|
+
|
|
386
|
+
// Directly update the certificate manager with the new routes
|
|
387
|
+
// This will extract domains and handle certificate provisioning
|
|
388
|
+
this.certificateManager.updateRouteConfigs(routes);
|
|
389
|
+
|
|
390
|
+
// Collect all domains and certificates for configuration
|
|
391
|
+
const currentHostnames = new Set<string>();
|
|
392
|
+
const certificateUpdates = new Map<string, { cert: string, key: string }>();
|
|
393
|
+
|
|
394
|
+
// Process each route to extract domain and certificate information
|
|
395
|
+
for (const route of routes) {
|
|
396
|
+
// Skip non-forward routes or routes without domains
|
|
397
|
+
if (route.action.type !== 'forward' || !route.match.domains) {
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Get domains from route
|
|
402
|
+
const domains = Array.isArray(route.match.domains)
|
|
403
|
+
? route.match.domains
|
|
404
|
+
: [route.match.domains];
|
|
405
|
+
|
|
406
|
+
// Process each domain
|
|
407
|
+
for (const domain of domains) {
|
|
408
|
+
// Skip wildcard domains for direct host configuration
|
|
409
|
+
if (domain.includes('*')) {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
currentHostnames.add(domain);
|
|
414
|
+
|
|
415
|
+
// Check if we have a static certificate for this domain
|
|
416
|
+
if (route.action.tls?.certificate && route.action.tls.certificate !== 'auto') {
|
|
417
|
+
certificateUpdates.set(domain, {
|
|
418
|
+
cert: route.action.tls.certificate.cert,
|
|
419
|
+
key: route.action.tls.certificate.key
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Update certificate cache with any static certificates
|
|
426
|
+
for (const [domain, certData] of certificateUpdates.entries()) {
|
|
346
427
|
try {
|
|
347
|
-
// Update certificate in cache
|
|
348
428
|
this.certificateManager.updateCertificateCache(
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
429
|
+
domain,
|
|
430
|
+
certData.cert,
|
|
431
|
+
certData.key
|
|
352
432
|
);
|
|
353
|
-
|
|
354
|
-
this.activeContexts.add(
|
|
433
|
+
|
|
434
|
+
this.activeContexts.add(domain);
|
|
355
435
|
} catch (error) {
|
|
356
|
-
this.logger.error(`Failed to add SSL context for ${
|
|
436
|
+
this.logger.error(`Failed to add SSL context for ${domain}`, error);
|
|
357
437
|
}
|
|
358
438
|
}
|
|
359
|
-
|
|
439
|
+
|
|
360
440
|
// Clean up removed contexts
|
|
361
441
|
for (const hostname of this.activeContexts) {
|
|
362
|
-
if (!
|
|
442
|
+
if (!currentHostnames.has(hostname)) {
|
|
363
443
|
this.logger.info(`Hostname ${hostname} removed from configuration`);
|
|
364
444
|
this.activeContexts.delete(hostname);
|
|
365
445
|
}
|
|
366
446
|
}
|
|
367
|
-
|
|
368
|
-
// Register domains with Port80Handler if available
|
|
369
|
-
const domainsForACME = Array.from(currentHostNames)
|
|
370
|
-
.filter(domain => !domain.includes('*')); // Skip wildcard domains
|
|
371
|
-
|
|
372
|
-
this.certificateManager.registerDomainsWithPort80Handler(domainsForACME);
|
|
373
|
-
}
|
|
374
447
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
for (const domainConfig of domainConfigs) {
|
|
397
|
-
// Each domain in the domains array gets its own config
|
|
398
|
-
for (const domain of domainConfig.domains) {
|
|
399
|
-
// Skip non-hostname patterns (like IP addresses)
|
|
400
|
-
if (domain.match(/^\d+\.\d+\.\d+\.\d+$/) || domain === '*' || domain === 'localhost') {
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
proxyConfigs.push({
|
|
405
|
-
hostName: domain,
|
|
406
|
-
destinationIps: domainConfig.targetIPs || ['localhost'],
|
|
407
|
-
destinationPorts: [this.options.port], // Use the NetworkProxy port
|
|
408
|
-
privateKey: sslKey,
|
|
409
|
-
publicKey: sslCert
|
|
410
|
-
});
|
|
448
|
+
// Create legacy proxy configs for the router
|
|
449
|
+
// This is only needed for backward compatibility with ProxyRouter
|
|
450
|
+
// and will be removed in the future
|
|
451
|
+
const legacyConfigs: IReverseProxyConfig[] = [];
|
|
452
|
+
|
|
453
|
+
for (const domain of currentHostnames) {
|
|
454
|
+
// Find route for this domain
|
|
455
|
+
const route = routes.find(r => {
|
|
456
|
+
const domains = Array.isArray(r.match.domains) ? r.match.domains : [r.match.domains];
|
|
457
|
+
return domains.includes(domain);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
if (!route || route.action.type !== 'forward' || !route.action.target) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// Skip routes with function-based targets - we'll handle them during request processing
|
|
465
|
+
if (typeof route.action.target.host === 'function' || typeof route.action.target.port === 'function') {
|
|
466
|
+
this.logger.info(`Domain ${domain} uses function-based targets - will be handled at request time`);
|
|
467
|
+
continue;
|
|
411
468
|
}
|
|
469
|
+
|
|
470
|
+
// Extract static target information
|
|
471
|
+
const targetHosts = Array.isArray(route.action.target.host)
|
|
472
|
+
? route.action.target.host
|
|
473
|
+
: [route.action.target.host];
|
|
474
|
+
|
|
475
|
+
const targetPort = route.action.target.port;
|
|
476
|
+
|
|
477
|
+
// Get certificate information
|
|
478
|
+
const certData = certificateUpdates.get(domain);
|
|
479
|
+
const defaultCerts = this.certificateManager.getDefaultCertificates();
|
|
480
|
+
|
|
481
|
+
legacyConfigs.push({
|
|
482
|
+
hostName: domain,
|
|
483
|
+
destinationIps: targetHosts,
|
|
484
|
+
destinationPorts: [targetPort],
|
|
485
|
+
privateKey: certData?.key || defaultCerts.key,
|
|
486
|
+
publicKey: certData?.cert || defaultCerts.cert
|
|
487
|
+
});
|
|
412
488
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
489
|
+
|
|
490
|
+
// Update the router with legacy configs
|
|
491
|
+
// Handle both old and new router interfaces
|
|
492
|
+
if (typeof this.router.setRoutes === 'function') {
|
|
493
|
+
this.router.setRoutes(routes);
|
|
494
|
+
} else if (typeof this.router.setNewProxyConfigs === 'function') {
|
|
495
|
+
this.router.setNewProxyConfigs(legacyConfigs);
|
|
496
|
+
} else {
|
|
497
|
+
this.logger.warn('Router has no recognized configuration method');
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
this.logger.info(`Route configuration updated with ${routes.length} routes and ${legacyConfigs.length} proxy configs`);
|
|
416
501
|
}
|
|
417
502
|
|
|
503
|
+
// Legacy methods have been removed.
|
|
504
|
+
// Please use updateRouteConfigs() directly with modern route-based configuration.
|
|
505
|
+
|
|
418
506
|
/**
|
|
419
507
|
* Adds default headers to be included in all responses
|
|
420
508
|
*/
|
|
@@ -474,11 +562,32 @@ export class NetworkProxy implements IMetricsTracker {
|
|
|
474
562
|
public async requestCertificate(domain: string): Promise<boolean> {
|
|
475
563
|
return this.certificateManager.requestCertificate(domain);
|
|
476
564
|
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Update certificate for a domain
|
|
568
|
+
*
|
|
569
|
+
* This method allows direct updates of certificates from external sources
|
|
570
|
+
* like Port80Handler or custom certificate providers.
|
|
571
|
+
*
|
|
572
|
+
* @param domain The domain to update certificate for
|
|
573
|
+
* @param certificate The new certificate (public key)
|
|
574
|
+
* @param privateKey The new private key
|
|
575
|
+
* @param expiryDate Optional expiry date
|
|
576
|
+
*/
|
|
577
|
+
public updateCertificate(
|
|
578
|
+
domain: string,
|
|
579
|
+
certificate: string,
|
|
580
|
+
privateKey: string,
|
|
581
|
+
expiryDate?: Date
|
|
582
|
+
): void {
|
|
583
|
+
this.logger.info(`Updating certificate for ${domain}`);
|
|
584
|
+
this.certificateManager.updateCertificateCache(domain, certificate, privateKey, expiryDate);
|
|
585
|
+
}
|
|
477
586
|
|
|
478
587
|
/**
|
|
479
|
-
* Gets all
|
|
588
|
+
* Gets all route configurations currently in use
|
|
480
589
|
*/
|
|
481
|
-
public
|
|
482
|
-
return
|
|
590
|
+
public getRouteConfigs(): IRouteConfig[] {
|
|
591
|
+
return this.routeManager.getRoutes();
|
|
483
592
|
}
|
|
484
593
|
}
|