@push.rocks/smartproxy 16.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/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/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 +3 -5
- package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +56 -3
- package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +4 -57
- package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +19 -228
- 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 +5 -0
- package/dist_ts/proxies/smart-proxy/route-connection-handler.js +131 -15
- package/dist_ts/proxies/smart-proxy/route-helpers/index.d.ts +3 -1
- package/dist_ts/proxies/smart-proxy/route-helpers/index.js +5 -3
- package/dist_ts/proxies/smart-proxy/route-helpers.d.ts +5 -178
- package/dist_ts/proxies/smart-proxy/route-helpers.js +8 -296
- package/dist_ts/proxies/smart-proxy/route-manager.d.ts +11 -2
- package/dist_ts/proxies/smart-proxy/route-manager.js +79 -10
- package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +29 -2
- package/dist_ts/proxies/smart-proxy/smart-proxy.js +48 -43
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +67 -1
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +120 -1
- package/dist_ts/proxies/smart-proxy/utils/route-validators.d.ts +3 -3
- package/dist_ts/proxies/smart-proxy/utils/route-validators.js +27 -5
- package/package.json +1 -1
- package/readme.md +102 -14
- package/readme.plan.md +103 -168
- package/ts/00_commitinfo_data.ts +1 -1
- 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/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 +7 -4
- package/ts/proxies/smart-proxy/models/route-types.ts +78 -10
- package/ts/proxies/smart-proxy/network-proxy-bridge.ts +20 -257
- package/ts/proxies/smart-proxy/port-manager.ts +195 -0
- package/ts/proxies/smart-proxy/route-connection-handler.ts +156 -21
- package/ts/proxies/smart-proxy/route-manager.ts +98 -14
- package/ts/proxies/smart-proxy/smart-proxy.ts +56 -55
- package/ts/proxies/smart-proxy/utils/route-helpers.ts +167 -1
- package/ts/proxies/smart-proxy/utils/route-validators.ts +24 -5
- package/ts/proxies/smart-proxy/domain-config-manager.ts.bak +0 -441
- package/ts/proxies/smart-proxy/route-helpers/index.ts +0 -9
- 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
|
|
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
|
|
37
|
-
|
|
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,43 @@ 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[]; //
|
|
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 | ((context: IRouteContext) => number); // Port with optional function for dynamic mapping
|
|
73
|
+
preservePort?: boolean; // Use incoming port as target port (ignored if port is a function)
|
|
44
74
|
}
|
|
45
75
|
|
|
46
76
|
/**
|
|
@@ -78,7 +108,8 @@ export interface IRouteAuthentication {
|
|
|
78
108
|
oauthClientId?: string;
|
|
79
109
|
oauthClientSecret?: string;
|
|
80
110
|
oauthRedirectUri?: string;
|
|
81
|
-
|
|
111
|
+
// Specific options for different auth types
|
|
112
|
+
options?: Record<string, unknown>;
|
|
82
113
|
}
|
|
83
114
|
|
|
84
115
|
/**
|
|
@@ -115,6 +146,16 @@ export interface IRouteTestResponse {
|
|
|
115
146
|
body: string;
|
|
116
147
|
}
|
|
117
148
|
|
|
149
|
+
/**
|
|
150
|
+
* URL rewriting configuration
|
|
151
|
+
*/
|
|
152
|
+
export interface IRouteUrlRewrite {
|
|
153
|
+
pattern: string; // RegExp pattern to match in URL
|
|
154
|
+
target: string; // Replacement pattern (supports template variables like {domain})
|
|
155
|
+
flags?: string; // RegExp flags like 'g' for global replacement
|
|
156
|
+
onlyRewritePath?: boolean; // Only apply to path, not query string
|
|
157
|
+
}
|
|
158
|
+
|
|
118
159
|
/**
|
|
119
160
|
* Advanced options for route actions
|
|
120
161
|
*/
|
|
@@ -124,6 +165,7 @@ export interface IRouteAdvanced {
|
|
|
124
165
|
keepAlive?: boolean;
|
|
125
166
|
staticFiles?: IRouteStaticFiles;
|
|
126
167
|
testResponse?: IRouteTestResponse;
|
|
168
|
+
urlRewrite?: IRouteUrlRewrite; // URL rewriting configuration
|
|
127
169
|
// Additional advanced options would go here
|
|
128
170
|
}
|
|
129
171
|
|
|
@@ -131,10 +173,15 @@ export interface IRouteAdvanced {
|
|
|
131
173
|
* WebSocket configuration
|
|
132
174
|
*/
|
|
133
175
|
export interface IRouteWebSocket {
|
|
134
|
-
enabled: boolean;
|
|
135
|
-
pingInterval?: number;
|
|
136
|
-
pingTimeout?: number;
|
|
137
|
-
maxPayloadSize?: number;
|
|
176
|
+
enabled: boolean; // Whether WebSockets are enabled for this route
|
|
177
|
+
pingInterval?: number; // Interval for sending ping frames (ms)
|
|
178
|
+
pingTimeout?: number; // Timeout for pong response (ms)
|
|
179
|
+
maxPayloadSize?: number; // Maximum message size in bytes
|
|
180
|
+
customHeaders?: Record<string, string>; // Custom headers for WebSocket handshake
|
|
181
|
+
subprotocols?: string[]; // Supported subprotocols
|
|
182
|
+
rewritePath?: string; // Path rewriting for WebSocket connections
|
|
183
|
+
allowedOrigins?: string[]; // Allowed origins for WebSocket connections
|
|
184
|
+
authenticateRequest?: boolean; // Whether to apply route security to WebSocket connections
|
|
138
185
|
}
|
|
139
186
|
|
|
140
187
|
/**
|
|
@@ -181,6 +228,12 @@ export interface IRouteAction {
|
|
|
181
228
|
|
|
182
229
|
// Advanced options
|
|
183
230
|
advanced?: IRouteAdvanced;
|
|
231
|
+
|
|
232
|
+
// Additional options for backend-specific settings
|
|
233
|
+
options?: {
|
|
234
|
+
backendProtocol?: 'http1' | 'http2';
|
|
235
|
+
[key: string]: any;
|
|
236
|
+
};
|
|
184
237
|
}
|
|
185
238
|
|
|
186
239
|
/**
|
|
@@ -219,12 +272,27 @@ export interface IRouteSecurity {
|
|
|
219
272
|
ipBlockList?: string[];
|
|
220
273
|
}
|
|
221
274
|
|
|
275
|
+
/**
|
|
276
|
+
* CORS configuration for a route
|
|
277
|
+
*/
|
|
278
|
+
export interface IRouteCors {
|
|
279
|
+
enabled: boolean; // Whether CORS is enabled for this route
|
|
280
|
+
allowOrigin?: string | string[]; // Allowed origins (*,domain.com,[domain1,domain2])
|
|
281
|
+
allowMethods?: string; // Allowed methods (GET,POST,etc.)
|
|
282
|
+
allowHeaders?: string; // Allowed headers
|
|
283
|
+
allowCredentials?: boolean; // Whether to allow credentials
|
|
284
|
+
exposeHeaders?: string; // Headers to expose to the client
|
|
285
|
+
maxAge?: number; // Preflight cache duration in seconds
|
|
286
|
+
preflight?: boolean; // Whether to respond to preflight requests
|
|
287
|
+
}
|
|
288
|
+
|
|
222
289
|
/**
|
|
223
290
|
* Headers configuration
|
|
224
291
|
*/
|
|
225
292
|
export interface IRouteHeaders {
|
|
226
|
-
request?: Record<string, string>;
|
|
227
|
-
response?: Record<string, string>;
|
|
293
|
+
request?: Record<string, string>; // Headers to add/modify for requests to backend
|
|
294
|
+
response?: Record<string, string>; // Headers to add/modify for responses to client
|
|
295
|
+
cors?: IRouteCors; // CORS configuration
|
|
228
296
|
}
|
|
229
297
|
|
|
230
298
|
/**
|
|
@@ -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
|
|
15
|
-
*
|
|
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
|
|
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
|
-
|
|
84
|
-
|
|
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
|
-
|
|
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
|
|
319
|
-
*
|
|
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
|
-
//
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|