@push.rocks/smartproxy 16.0.2 → 16.0.4

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 (115) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/core/models/index.d.ts +2 -0
  3. package/dist_ts/core/models/index.js +3 -1
  4. package/dist_ts/core/models/route-context.d.ts +62 -0
  5. package/dist_ts/core/models/route-context.js +43 -0
  6. package/dist_ts/core/models/socket-augmentation.d.ts +12 -0
  7. package/dist_ts/core/models/socket-augmentation.js +18 -0
  8. package/dist_ts/core/utils/event-system.d.ts +200 -0
  9. package/dist_ts/core/utils/event-system.js +224 -0
  10. package/dist_ts/core/utils/index.d.ts +7 -0
  11. package/dist_ts/core/utils/index.js +8 -1
  12. package/dist_ts/core/utils/route-manager.d.ts +118 -0
  13. package/dist_ts/core/utils/route-manager.js +383 -0
  14. package/dist_ts/core/utils/route-utils.d.ts +94 -0
  15. package/dist_ts/core/utils/route-utils.js +264 -0
  16. package/dist_ts/core/utils/security-utils.d.ts +111 -0
  17. package/dist_ts/core/utils/security-utils.js +212 -0
  18. package/dist_ts/core/utils/shared-security-manager.d.ts +110 -0
  19. package/dist_ts/core/utils/shared-security-manager.js +252 -0
  20. package/dist_ts/core/utils/template-utils.d.ts +37 -0
  21. package/dist_ts/core/utils/template-utils.js +104 -0
  22. package/dist_ts/core/utils/websocket-utils.d.ts +23 -0
  23. package/dist_ts/core/utils/websocket-utils.js +86 -0
  24. package/dist_ts/http/router/index.d.ts +5 -1
  25. package/dist_ts/http/router/index.js +4 -2
  26. package/dist_ts/http/router/route-router.d.ts +108 -0
  27. package/dist_ts/http/router/route-router.js +393 -0
  28. package/dist_ts/index.d.ts +8 -2
  29. package/dist_ts/index.js +10 -3
  30. package/dist_ts/proxies/index.d.ts +7 -2
  31. package/dist_ts/proxies/index.js +10 -4
  32. package/dist_ts/proxies/network-proxy/certificate-manager.d.ts +21 -0
  33. package/dist_ts/proxies/network-proxy/certificate-manager.js +92 -1
  34. package/dist_ts/proxies/network-proxy/context-creator.d.ts +34 -0
  35. package/dist_ts/proxies/network-proxy/context-creator.js +108 -0
  36. package/dist_ts/proxies/network-proxy/function-cache.d.ts +90 -0
  37. package/dist_ts/proxies/network-proxy/function-cache.js +198 -0
  38. package/dist_ts/proxies/network-proxy/http-request-handler.d.ts +40 -0
  39. package/dist_ts/proxies/network-proxy/http-request-handler.js +256 -0
  40. package/dist_ts/proxies/network-proxy/http2-request-handler.d.ts +24 -0
  41. package/dist_ts/proxies/network-proxy/http2-request-handler.js +201 -0
  42. package/dist_ts/proxies/network-proxy/models/types.d.ts +73 -1
  43. package/dist_ts/proxies/network-proxy/models/types.js +242 -1
  44. package/dist_ts/proxies/network-proxy/network-proxy.d.ts +23 -20
  45. package/dist_ts/proxies/network-proxy/network-proxy.js +149 -60
  46. package/dist_ts/proxies/network-proxy/request-handler.d.ts +38 -5
  47. package/dist_ts/proxies/network-proxy/request-handler.js +584 -198
  48. package/dist_ts/proxies/network-proxy/security-manager.d.ts +65 -0
  49. package/dist_ts/proxies/network-proxy/security-manager.js +255 -0
  50. package/dist_ts/proxies/network-proxy/websocket-handler.d.ts +13 -2
  51. package/dist_ts/proxies/network-proxy/websocket-handler.js +238 -20
  52. package/dist_ts/proxies/smart-proxy/index.d.ts +1 -1
  53. package/dist_ts/proxies/smart-proxy/index.js +3 -3
  54. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +3 -5
  55. package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +56 -4
  56. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +4 -57
  57. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +19 -228
  58. package/dist_ts/proxies/smart-proxy/port-manager.d.ts +81 -0
  59. package/dist_ts/proxies/smart-proxy/port-manager.js +166 -0
  60. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +5 -0
  61. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +131 -15
  62. package/dist_ts/proxies/smart-proxy/route-helpers/index.d.ts +3 -1
  63. package/dist_ts/proxies/smart-proxy/route-helpers/index.js +5 -3
  64. package/dist_ts/proxies/smart-proxy/route-helpers.d.ts +5 -178
  65. package/dist_ts/proxies/smart-proxy/route-helpers.js +8 -296
  66. package/dist_ts/proxies/smart-proxy/route-manager.d.ts +11 -2
  67. package/dist_ts/proxies/smart-proxy/route-manager.js +79 -10
  68. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +29 -2
  69. package/dist_ts/proxies/smart-proxy/smart-proxy.js +48 -43
  70. package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +67 -1
  71. package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +120 -1
  72. package/dist_ts/proxies/smart-proxy/utils/route-validators.d.ts +3 -3
  73. package/dist_ts/proxies/smart-proxy/utils/route-validators.js +27 -5
  74. package/package.json +1 -1
  75. package/readme.md +102 -14
  76. package/readme.plan.md +103 -168
  77. package/ts/00_commitinfo_data.ts +1 -1
  78. package/ts/core/models/index.ts +2 -0
  79. package/ts/core/models/route-context.ts +113 -0
  80. package/ts/core/models/socket-augmentation.ts +33 -0
  81. package/ts/core/utils/event-system.ts +376 -0
  82. package/ts/core/utils/index.ts +7 -0
  83. package/ts/core/utils/route-manager.ts +489 -0
  84. package/ts/core/utils/route-utils.ts +312 -0
  85. package/ts/core/utils/security-utils.ts +309 -0
  86. package/ts/core/utils/shared-security-manager.ts +333 -0
  87. package/ts/core/utils/template-utils.ts +124 -0
  88. package/ts/core/utils/websocket-utils.ts +81 -0
  89. package/ts/http/router/index.ts +8 -1
  90. package/ts/http/router/route-router.ts +482 -0
  91. package/ts/index.ts +14 -2
  92. package/ts/proxies/index.ts +12 -3
  93. package/ts/proxies/network-proxy/certificate-manager.ts +114 -10
  94. package/ts/proxies/network-proxy/context-creator.ts +145 -0
  95. package/ts/proxies/network-proxy/function-cache.ts +259 -0
  96. package/ts/proxies/network-proxy/http-request-handler.ts +330 -0
  97. package/ts/proxies/network-proxy/http2-request-handler.ts +255 -0
  98. package/ts/proxies/network-proxy/models/types.ts +312 -1
  99. package/ts/proxies/network-proxy/network-proxy.ts +197 -85
  100. package/ts/proxies/network-proxy/request-handler.ts +698 -246
  101. package/ts/proxies/network-proxy/security-manager.ts +298 -0
  102. package/ts/proxies/network-proxy/websocket-handler.ts +276 -33
  103. package/ts/proxies/smart-proxy/index.ts +2 -12
  104. package/ts/proxies/smart-proxy/models/interfaces.ts +7 -4
  105. package/ts/proxies/smart-proxy/models/route-types.ts +77 -10
  106. package/ts/proxies/smart-proxy/network-proxy-bridge.ts +20 -257
  107. package/ts/proxies/smart-proxy/port-manager.ts +195 -0
  108. package/ts/proxies/smart-proxy/route-connection-handler.ts +156 -21
  109. package/ts/proxies/smart-proxy/route-manager.ts +98 -14
  110. package/ts/proxies/smart-proxy/smart-proxy.ts +56 -55
  111. package/ts/proxies/smart-proxy/utils/route-helpers.ts +167 -1
  112. package/ts/proxies/smart-proxy/utils/route-validators.ts +24 -5
  113. package/ts/proxies/smart-proxy/domain-config-manager.ts.bak +0 -441
  114. package/ts/proxies/smart-proxy/route-helpers/index.ts +0 -9
  115. package/ts/proxies/smart-proxy/route-helpers.ts +0 -498
@@ -20,15 +20,5 @@ export { NetworkProxyBridge } from './network-proxy-bridge.js';
20
20
  export { RouteManager } from './route-manager.js';
21
21
  export { RouteConnectionHandler } from './route-connection-handler.js';
22
22
 
23
- // Export route helpers for configuration
24
- export {
25
- createRoute,
26
- createHttpRoute,
27
- createHttpsRoute,
28
- createPassthroughRoute,
29
- createRedirectRoute,
30
- createHttpToHttpsRedirect,
31
- createBlockRoute,
32
- createLoadBalancerRoute,
33
- createHttpsServer
34
- } from './route-helpers.js';
23
+ // Export all helper functions from the utils directory
24
+ export * from './utils/index.js';
@@ -33,10 +33,8 @@ export interface ISmartProxyOptions {
33
33
  // The unified configuration array (required)
34
34
  routes: IRouteConfig[];
35
35
 
36
- // Port range configuration
37
- globalPortRanges?: Array<{ from: number; to: number }>;
38
- forwardAllGlobalRanges?: boolean;
39
- preserveSourceIP?: boolean;
36
+ // Port configuration
37
+ preserveSourceIP?: boolean; // Preserve client IP when forwarding
40
38
 
41
39
  // Global/default settings
42
40
  defaults?: {
@@ -140,6 +138,11 @@ export interface IConnectionRecord {
140
138
  hasReceivedInitialData: boolean; // Whether initial data has been received
141
139
  routeConfig?: IRouteConfig; // Associated route config for this connection
142
140
 
141
+ // Target information (for dynamic port/host mapping)
142
+ targetHost?: string; // Resolved target host
143
+ targetPort?: number; // Resolved target port
144
+ tlsVersion?: string; // TLS version (for routing context)
145
+
143
146
  // Keep-alive tracking
144
147
  hasKeepAlive: boolean; // Whether keep-alive is enabled for this connection
145
148
  inactivityWarningIssued?: boolean; // Whether an inactivity warning has been issued
@@ -34,13 +34,42 @@ export interface IRouteMatch {
34
34
  headers?: Record<string, string | RegExp>; // Match specific HTTP headers
35
35
  }
36
36
 
37
+ /**
38
+ * Context provided to port and host mapping functions
39
+ */
40
+ export interface IRouteContext {
41
+ // Connection information
42
+ port: number; // The matched incoming port
43
+ domain?: string; // The domain from SNI or Host header
44
+ clientIp: string; // The client's IP address
45
+ serverIp: string; // The server's IP address
46
+ path?: string; // URL path (for HTTP connections)
47
+ query?: string; // Query string (for HTTP connections)
48
+ headers?: Record<string, string>; // HTTP headers (for HTTP connections)
49
+
50
+ // TLS information
51
+ isTls: boolean; // Whether the connection is TLS
52
+ tlsVersion?: string; // TLS version if applicable
53
+
54
+ // Route information
55
+ routeName?: string; // The name of the matched route
56
+ routeId?: string; // The ID of the matched route
57
+
58
+ // Target information (resolved from dynamic mapping)
59
+ targetHost?: string | string[]; // The resolved target host(s)
60
+ targetPort?: number; // The resolved target port
61
+
62
+ // Additional properties
63
+ timestamp: number; // The request timestamp
64
+ connectionId: string; // Unique connection identifier
65
+ }
66
+
37
67
  /**
38
68
  * Target configuration for forwarding
39
69
  */
40
70
  export interface IRouteTarget {
41
- host: string | string[]; // Support single host or round-robin
42
- port: number;
43
- preservePort?: boolean; // Use incoming port as target port
71
+ host: string | string[] | ((context: IRouteContext) => string | string[]); // Host or hosts with optional function for dynamic resolution
72
+ port: number | 'preserve' | ((context: IRouteContext) => number); // Port with optional function for dynamic mapping (use 'preserve' to keep the incoming port)
44
73
  }
45
74
 
46
75
  /**
@@ -78,7 +107,8 @@ export interface IRouteAuthentication {
78
107
  oauthClientId?: string;
79
108
  oauthClientSecret?: string;
80
109
  oauthRedirectUri?: string;
81
- [key: string]: any; // Allow additional auth-specific options
110
+ // Specific options for different auth types
111
+ options?: Record<string, unknown>;
82
112
  }
83
113
 
84
114
  /**
@@ -115,6 +145,16 @@ export interface IRouteTestResponse {
115
145
  body: string;
116
146
  }
117
147
 
148
+ /**
149
+ * URL rewriting configuration
150
+ */
151
+ export interface IRouteUrlRewrite {
152
+ pattern: string; // RegExp pattern to match in URL
153
+ target: string; // Replacement pattern (supports template variables like {domain})
154
+ flags?: string; // RegExp flags like 'g' for global replacement
155
+ onlyRewritePath?: boolean; // Only apply to path, not query string
156
+ }
157
+
118
158
  /**
119
159
  * Advanced options for route actions
120
160
  */
@@ -124,6 +164,7 @@ export interface IRouteAdvanced {
124
164
  keepAlive?: boolean;
125
165
  staticFiles?: IRouteStaticFiles;
126
166
  testResponse?: IRouteTestResponse;
167
+ urlRewrite?: IRouteUrlRewrite; // URL rewriting configuration
127
168
  // Additional advanced options would go here
128
169
  }
129
170
 
@@ -131,10 +172,15 @@ export interface IRouteAdvanced {
131
172
  * WebSocket configuration
132
173
  */
133
174
  export interface IRouteWebSocket {
134
- enabled: boolean;
135
- pingInterval?: number;
136
- pingTimeout?: number;
137
- maxPayloadSize?: number;
175
+ enabled: boolean; // Whether WebSockets are enabled for this route
176
+ pingInterval?: number; // Interval for sending ping frames (ms)
177
+ pingTimeout?: number; // Timeout for pong response (ms)
178
+ maxPayloadSize?: number; // Maximum message size in bytes
179
+ customHeaders?: Record<string, string>; // Custom headers for WebSocket handshake
180
+ subprotocols?: string[]; // Supported subprotocols
181
+ rewritePath?: string; // Path rewriting for WebSocket connections
182
+ allowedOrigins?: string[]; // Allowed origins for WebSocket connections
183
+ authenticateRequest?: boolean; // Whether to apply route security to WebSocket connections
138
184
  }
139
185
 
140
186
  /**
@@ -181,6 +227,12 @@ export interface IRouteAction {
181
227
 
182
228
  // Advanced options
183
229
  advanced?: IRouteAdvanced;
230
+
231
+ // Additional options for backend-specific settings
232
+ options?: {
233
+ backendProtocol?: 'http1' | 'http2';
234
+ [key: string]: any;
235
+ };
184
236
  }
185
237
 
186
238
  /**
@@ -219,12 +271,27 @@ export interface IRouteSecurity {
219
271
  ipBlockList?: string[];
220
272
  }
221
273
 
274
+ /**
275
+ * CORS configuration for a route
276
+ */
277
+ export interface IRouteCors {
278
+ enabled: boolean; // Whether CORS is enabled for this route
279
+ allowOrigin?: string | string[]; // Allowed origins (*,domain.com,[domain1,domain2])
280
+ allowMethods?: string; // Allowed methods (GET,POST,etc.)
281
+ allowHeaders?: string; // Allowed headers
282
+ allowCredentials?: boolean; // Whether to allow credentials
283
+ exposeHeaders?: string; // Headers to expose to the client
284
+ maxAge?: number; // Preflight cache duration in seconds
285
+ preflight?: boolean; // Whether to respond to preflight requests
286
+ }
287
+
222
288
  /**
223
289
  * Headers configuration
224
290
  */
225
291
  export interface IRouteHeaders {
226
- request?: Record<string, string>;
227
- response?: Record<string, string>;
292
+ request?: Record<string, string>; // Headers to add/modify for requests to backend
293
+ response?: Record<string, string>; // Headers to add/modify for responses to client
294
+ cors?: IRouteCors; // CORS configuration
228
295
  }
229
296
 
230
297
  /**
@@ -1,7 +1,6 @@
1
1
  import * as plugins from '../../plugins.js';
2
2
  import { NetworkProxy } from '../network-proxy/index.js';
3
3
  import { Port80Handler } from '../../http/port80/port80-handler.js';
4
- import { Port80HandlerEvents } from '../../core/models/common-types.js';
5
4
  import { subscribeToPort80Handler } from '../../core/utils/event-utils.js';
6
5
  import type { ICertificateData } from '../../certificate/models/certificate-types.js';
7
6
  import type { IConnectionRecord, ISmartProxyOptions } from './models/interfaces.js';
@@ -11,8 +10,8 @@ import type { IRouteConfig } from './models/route-types.js';
11
10
  * Manages NetworkProxy integration for TLS termination
12
11
  *
13
12
  * NetworkProxyBridge connects SmartProxy with NetworkProxy to handle TLS termination.
14
- * It directly maps route configurations to NetworkProxy configuration format and manages
15
- * certificate provisioning through Port80Handler when ACME is enabled.
13
+ * It directly passes route configurations to NetworkProxy and manages the physical
14
+ * connection piping between SmartProxy and NetworkProxy for TLS termination.
16
15
  *
17
16
  * It is used by SmartProxy for routes that have:
18
17
  * - TLS mode of 'terminate' or 'terminate-and-reencrypt'
@@ -49,7 +48,7 @@ export class NetworkProxyBridge {
49
48
  */
50
49
  public async initialize(): Promise<void> {
51
50
  if (!this.networkProxy && this.settings.useNetworkProxy && this.settings.useNetworkProxy.length > 0) {
52
- // Configure NetworkProxy options based on PortProxy settings
51
+ // Configure NetworkProxy options based on SmartProxy settings
53
52
  const networkProxyOptions: any = {
54
53
  port: this.settings.networkProxyPort!,
55
54
  portProxyIntegration: true,
@@ -57,7 +56,6 @@ export class NetworkProxyBridge {
57
56
  useExternalPort80Handler: !!this.port80Handler // Use Port80Handler if available
58
57
  };
59
58
 
60
-
61
59
  this.networkProxy = new NetworkProxy(networkProxyOptions);
62
60
 
63
61
  console.log(`Initialized NetworkProxy on port ${this.settings.networkProxyPort}`);
@@ -80,29 +78,8 @@ export class NetworkProxyBridge {
80
78
 
81
79
  console.log(`Received certificate for ${data.domain} from Port80Handler, updating NetworkProxy`);
82
80
 
83
- try {
84
- // Find existing config for this domain
85
- const existingConfigs = this.networkProxy.getProxyConfigs()
86
- .filter(config => config.hostName === data.domain);
87
-
88
- if (existingConfigs.length > 0) {
89
- // Update existing configs with new certificate
90
- for (const config of existingConfigs) {
91
- config.privateKey = data.privateKey;
92
- config.publicKey = data.certificate;
93
- }
94
-
95
- // Apply updated configs
96
- this.networkProxy.updateProxyConfigs(existingConfigs)
97
- .then(() => console.log(`Updated certificate for ${data.domain} in NetworkProxy`))
98
- .catch(err => console.log(`Error updating certificate in NetworkProxy: ${err}`));
99
- } else {
100
- // Create a new config for this domain
101
- console.log(`No existing config found for ${data.domain}, creating new config in NetworkProxy`);
102
- }
103
- } catch (err) {
104
- console.log(`Error handling certificate event: ${err}`);
105
- }
81
+ // Apply certificate directly to NetworkProxy
82
+ this.networkProxy.updateCertificate(data.domain, data.certificate, data.privateKey);
106
83
  }
107
84
 
108
85
  /**
@@ -113,7 +90,9 @@ export class NetworkProxyBridge {
113
90
  console.log(`NetworkProxy not initialized: cannot apply external certificate for ${data.domain}`);
114
91
  return;
115
92
  }
116
- this.handleCertificateEvent(data);
93
+
94
+ // Apply certificate directly to NetworkProxy
95
+ this.networkProxy.updateCertificate(data.domain, data.certificate, data.privateKey);
117
96
  }
118
97
 
119
98
  /**
@@ -155,92 +134,6 @@ export class NetworkProxyBridge {
155
134
  }
156
135
  }
157
136
 
158
- /**
159
- * Register domains from routes with Port80Handler for certificate management
160
- *
161
- * Extracts domains from routes that require TLS termination and registers them
162
- * with the Port80Handler for certificate issuance and renewal.
163
- *
164
- * @param routes The route configurations to extract domains from
165
- */
166
- public registerDomainsWithPort80Handler(routes: IRouteConfig[]): void {
167
- if (!this.port80Handler) {
168
- console.log('Cannot register domains - Port80Handler not initialized');
169
- return;
170
- }
171
-
172
- // Extract domains from routes that require TLS termination
173
- const domainsToRegister = new Set<string>();
174
-
175
- for (const route of routes) {
176
- // Skip routes without domains or TLS configuration
177
- if (!route.match.domains || !route.action.tls) continue;
178
-
179
- // Only register domains for routes that terminate TLS
180
- if (route.action.tls.mode !== 'terminate' && route.action.tls.mode !== 'terminate-and-reencrypt') continue;
181
-
182
- // Extract domains from route
183
- const domains = Array.isArray(route.match.domains)
184
- ? route.match.domains
185
- : [route.match.domains];
186
-
187
- // Add each domain to the set (avoiding duplicates)
188
- for (const domain of domains) {
189
- // Skip wildcards
190
- if (domain.includes('*')) {
191
- console.log(`Skipping wildcard domain for ACME: ${domain}`);
192
- continue;
193
- }
194
-
195
- domainsToRegister.add(domain);
196
- }
197
- }
198
-
199
- // Register each unique domain with Port80Handler
200
- for (const domain of domainsToRegister) {
201
- try {
202
- this.port80Handler.addDomain({
203
- domainName: domain,
204
- sslRedirect: true,
205
- acmeMaintenance: true,
206
- // Include route reference if we can find it
207
- routeReference: this.findRouteReferenceForDomain(domain, routes)
208
- });
209
-
210
- console.log(`Registered domain with Port80Handler: ${domain}`);
211
- } catch (err) {
212
- console.log(`Error registering domain ${domain} with Port80Handler: ${err}`);
213
- }
214
- }
215
- }
216
-
217
- /**
218
- * Finds the route reference for a given domain
219
- *
220
- * @param domain The domain to find a route reference for
221
- * @param routes The routes to search
222
- * @returns The route reference if found, undefined otherwise
223
- */
224
- private findRouteReferenceForDomain(domain: string, routes: IRouteConfig[]): { routeId?: string; routeName?: string } | undefined {
225
- // Find the first route that matches this domain
226
- for (const route of routes) {
227
- if (!route.match.domains) continue;
228
-
229
- const domains = Array.isArray(route.match.domains)
230
- ? route.match.domains
231
- : [route.match.domains];
232
-
233
- if (domains.includes(domain)) {
234
- return {
235
- routeId: undefined, // No explicit IDs in our current routes
236
- routeName: route.name
237
- };
238
- }
239
- }
240
-
241
- return undefined;
242
- }
243
-
244
137
  /**
245
138
  * Forwards a TLS connection to a NetworkProxy for handling
246
139
  */
@@ -305,7 +198,6 @@ export class NetworkProxyBridge {
305
198
  socket.pipe(proxySocket);
306
199
  proxySocket.pipe(socket);
307
200
 
308
- // Update activity on data transfer (caller should handle this)
309
201
  if (this.settings.enableDetailedLogging) {
310
202
  console.log(`[${connectionId}] TLS connection successfully forwarded to NetworkProxy`);
311
203
  }
@@ -315,13 +207,8 @@ export class NetworkProxyBridge {
315
207
  /**
316
208
  * Synchronizes routes to NetworkProxy
317
209
  *
318
- * This method directly maps route configurations to NetworkProxy format and updates
319
- * the NetworkProxy with these configurations. It handles:
320
- *
321
- * - Extracting domain, target, and certificate information from routes
322
- * - Converting TLS mode settings to NetworkProxy configuration
323
- * - Applying security and advanced settings
324
- * - Registering domains for ACME certificate provisioning when needed
210
+ * This method directly passes route configurations to NetworkProxy without any
211
+ * intermediate conversion. NetworkProxy natively understands route configurations.
325
212
  *
326
213
  * @param routes The route configurations to sync to NetworkProxy
327
214
  */
@@ -332,140 +219,22 @@ export class NetworkProxyBridge {
332
219
  }
333
220
 
334
221
  try {
335
- // Get SSL certificates from assets
336
- // Import fs directly since it's not in plugins
337
- const fs = await import('fs');
338
-
339
- let defaultCertPair;
340
- try {
341
- defaultCertPair = {
342
- key: fs.readFileSync('assets/certs/key.pem', 'utf8'),
343
- cert: fs.readFileSync('assets/certs/cert.pem', 'utf8'),
344
- };
345
- } catch (certError) {
346
- console.log(`Warning: Could not read default certificates: ${certError}`);
347
- console.log(
348
- 'Using empty certificate placeholders - ACME will generate proper certificates if enabled'
222
+ // Filter only routes that are applicable to NetworkProxy (TLS termination)
223
+ const networkProxyRoutes = routes.filter(route => {
224
+ return (
225
+ route.action.type === 'forward' &&
226
+ route.action.tls &&
227
+ (route.action.tls.mode === 'terminate' || route.action.tls.mode === 'terminate-and-reencrypt')
349
228
  );
229
+ });
350
230
 
351
- // Use empty placeholders - NetworkProxy will use its internal defaults
352
- // or ACME will generate proper ones if enabled
353
- defaultCertPair = {
354
- key: '',
355
- cert: '',
356
- };
357
- }
358
-
359
- // Map routes directly to NetworkProxy configs
360
- const proxyConfigs = this.mapRoutesToNetworkProxyConfigs(routes, defaultCertPair);
361
-
362
- // Update the proxy configs
363
- await this.networkProxy.updateProxyConfigs(proxyConfigs);
364
- console.log(`Synced ${proxyConfigs.length} configurations to NetworkProxy`);
365
-
366
- // Register domains with Port80Handler for certificate issuance
367
- if (this.port80Handler) {
368
- this.registerDomainsWithPort80Handler(routes);
369
- }
231
+ // Pass routes directly to NetworkProxy
232
+ await this.networkProxy.updateRouteConfigs(networkProxyRoutes);
233
+ console.log(`Synced ${networkProxyRoutes.length} routes directly to NetworkProxy`);
370
234
  } catch (err) {
371
235
  console.log(`Error syncing routes to NetworkProxy: ${err}`);
372
236
  }
373
237
  }
374
-
375
- /**
376
- * Map routes directly to NetworkProxy configuration format
377
- *
378
- * This method directly maps route configurations to NetworkProxy's format
379
- * without any intermediate domain-based representation. It processes each route
380
- * and creates appropriate NetworkProxy configs for domains that require TLS termination.
381
- *
382
- * @param routes Array of route configurations to map
383
- * @param defaultCertPair Default certificate to use if no custom certificate is specified
384
- * @returns Array of NetworkProxy configurations
385
- */
386
- public mapRoutesToNetworkProxyConfigs(
387
- routes: IRouteConfig[],
388
- defaultCertPair: { key: string; cert: string }
389
- ): plugins.tsclass.network.IReverseProxyConfig[] {
390
- const configs: plugins.tsclass.network.IReverseProxyConfig[] = [];
391
-
392
- for (const route of routes) {
393
- // Skip routes without domains
394
- if (!route.match.domains) continue;
395
-
396
- // Skip non-forward routes
397
- if (route.action.type !== 'forward') continue;
398
-
399
- // Skip routes without TLS configuration
400
- if (!route.action.tls || !route.action.target) continue;
401
-
402
- // Skip routes that don't require TLS termination
403
- if (route.action.tls.mode !== 'terminate' && route.action.tls.mode !== 'terminate-and-reencrypt') continue;
404
-
405
- // Get domains from route
406
- const domains = Array.isArray(route.match.domains)
407
- ? route.match.domains
408
- : [route.match.domains];
409
-
410
- // Create a config for each domain
411
- for (const domain of domains) {
412
- // Get certificate
413
- let certKey = defaultCertPair.key;
414
- let certCert = defaultCertPair.cert;
415
-
416
- // Use custom certificate if specified
417
- if (route.action.tls.certificate !== 'auto' && typeof route.action.tls.certificate === 'object') {
418
- certKey = route.action.tls.certificate.key;
419
- certCert = route.action.tls.certificate.cert;
420
- }
421
-
422
- // Determine target hosts and ports
423
- const targetHosts = Array.isArray(route.action.target.host)
424
- ? route.action.target.host
425
- : [route.action.target.host];
426
-
427
- const targetPort = route.action.target.port;
428
-
429
- // Create the NetworkProxy config
430
- const config: plugins.tsclass.network.IReverseProxyConfig = {
431
- hostName: domain,
432
- privateKey: certKey,
433
- publicKey: certCert,
434
- destinationIps: targetHosts,
435
- destinationPorts: [targetPort]
436
- // Note: We can't include additional metadata as it's not supported in the interface
437
- };
438
-
439
- configs.push(config);
440
- }
441
- }
442
-
443
- return configs;
444
- }
445
-
446
- /**
447
- * @deprecated This method is kept for backward compatibility.
448
- * Use mapRoutesToNetworkProxyConfigs() instead.
449
- */
450
- public convertRoutesToNetworkProxyConfigs(
451
- routes: IRouteConfig[],
452
- defaultCertPair: { key: string; cert: string }
453
- ): plugins.tsclass.network.IReverseProxyConfig[] {
454
- return this.mapRoutesToNetworkProxyConfigs(routes, defaultCertPair);
455
- }
456
-
457
- /**
458
- * @deprecated This method is deprecated and will be removed in a future version.
459
- * Use syncRoutesToNetworkProxy() instead.
460
- *
461
- * This legacy method exists only for backward compatibility and
462
- * simply forwards to syncRoutesToNetworkProxy().
463
- */
464
- public async syncDomainConfigsToNetworkProxy(): Promise<void> {
465
- console.log('DEPRECATED: Method syncDomainConfigsToNetworkProxy will be removed in a future version.');
466
- console.log('Please use syncRoutesToNetworkProxy() instead for direct route-based configuration.');
467
- await this.syncRoutesToNetworkProxy(this.settings.routes || []);
468
- }
469
238
 
470
239
  /**
471
240
  * Request a certificate for a specific domain
@@ -496,12 +265,6 @@ export class NetworkProxyBridge {
496
265
  domainOptions.routeReference = {
497
266
  routeName
498
267
  };
499
- } else {
500
- // Try to find a route reference from the current routes
501
- const routeReference = this.findRouteReferenceForDomain(domain, this.settings.routes || []);
502
- if (routeReference) {
503
- domainOptions.routeReference = routeReference;
504
- }
505
268
  }
506
269
 
507
270
  // Register the domain for certificate issuance