@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
|
@@ -7,8 +7,7 @@ import type {
|
|
|
7
7
|
} from './models/route-types.js';
|
|
8
8
|
import type {
|
|
9
9
|
ISmartProxyOptions,
|
|
10
|
-
IRoutedSmartProxyOptions
|
|
11
|
-
IDomainConfig
|
|
10
|
+
IRoutedSmartProxyOptions
|
|
12
11
|
} from './models/interfaces.js';
|
|
13
12
|
import {
|
|
14
13
|
isRoutedOptions,
|
|
@@ -59,36 +58,88 @@ export class RouteManager extends plugins.EventEmitter {
|
|
|
59
58
|
|
|
60
59
|
/**
|
|
61
60
|
* Rebuild the port mapping for fast lookups
|
|
61
|
+
* Also logs information about the ports being listened on
|
|
62
62
|
*/
|
|
63
63
|
private rebuildPortMap(): void {
|
|
64
64
|
this.portMap.clear();
|
|
65
|
-
|
|
65
|
+
this.portRangeCache.clear(); // Clear cache when rebuilding
|
|
66
|
+
|
|
67
|
+
// Track ports for logging
|
|
68
|
+
const portToRoutesMap = new Map<number, string[]>();
|
|
69
|
+
|
|
66
70
|
for (const route of this.routes) {
|
|
67
71
|
const ports = this.expandPortRange(route.match.ports);
|
|
68
|
-
|
|
72
|
+
|
|
73
|
+
// Skip if no ports were found
|
|
74
|
+
if (ports.length === 0) {
|
|
75
|
+
console.warn(`Route ${route.name || 'unnamed'} has no valid ports to listen on`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
for (const port of ports) {
|
|
80
|
+
// Add to portMap for routing
|
|
70
81
|
if (!this.portMap.has(port)) {
|
|
71
82
|
this.portMap.set(port, []);
|
|
72
83
|
}
|
|
73
84
|
this.portMap.get(port)!.push(route);
|
|
85
|
+
|
|
86
|
+
// Add to tracking for logging
|
|
87
|
+
if (!portToRoutesMap.has(port)) {
|
|
88
|
+
portToRoutesMap.set(port, []);
|
|
89
|
+
}
|
|
90
|
+
portToRoutesMap.get(port)!.push(route.name || 'unnamed');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Log summary of ports and routes
|
|
95
|
+
const totalPorts = this.portMap.size;
|
|
96
|
+
const totalRoutes = this.routes.length;
|
|
97
|
+
console.log(`Route manager configured with ${totalRoutes} routes across ${totalPorts} ports`);
|
|
98
|
+
|
|
99
|
+
// Log port details if detailed logging is enabled
|
|
100
|
+
const enableDetailedLogging = this.options.enableDetailedLogging;
|
|
101
|
+
if (enableDetailedLogging) {
|
|
102
|
+
for (const [port, routes] of this.portMap.entries()) {
|
|
103
|
+
console.log(`Port ${port}: ${routes.length} routes (${portToRoutesMap.get(port)!.join(', ')})`);
|
|
74
104
|
}
|
|
75
105
|
}
|
|
76
106
|
}
|
|
77
107
|
|
|
78
108
|
/**
|
|
79
109
|
* Expand a port range specification into an array of individual ports
|
|
110
|
+
* Uses caching to improve performance for frequently used port ranges
|
|
111
|
+
*
|
|
112
|
+
* @public - Made public to allow external code to interpret port ranges
|
|
80
113
|
*/
|
|
81
|
-
|
|
114
|
+
public expandPortRange(portRange: TPortRange): number[] {
|
|
115
|
+
// For simple number, return immediately
|
|
82
116
|
if (typeof portRange === 'number') {
|
|
83
117
|
return [portRange];
|
|
84
118
|
}
|
|
85
|
-
|
|
119
|
+
|
|
120
|
+
// Create a cache key for this port range
|
|
121
|
+
const cacheKey = JSON.stringify(portRange);
|
|
122
|
+
|
|
123
|
+
// Check if we have a cached result
|
|
124
|
+
if (this.portRangeCache.has(cacheKey)) {
|
|
125
|
+
return this.portRangeCache.get(cacheKey)!;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Process the port range
|
|
129
|
+
let result: number[] = [];
|
|
130
|
+
|
|
86
131
|
if (Array.isArray(portRange)) {
|
|
87
132
|
// Handle array of port objects or numbers
|
|
88
|
-
|
|
133
|
+
result = portRange.flatMap(item => {
|
|
89
134
|
if (typeof item === 'number') {
|
|
90
135
|
return [item];
|
|
91
136
|
} else if (typeof item === 'object' && 'from' in item && 'to' in item) {
|
|
137
|
+
// Handle port range object - check valid range
|
|
138
|
+
if (item.from > item.to) {
|
|
139
|
+
console.warn(`Invalid port range: from (${item.from}) > to (${item.to})`);
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
|
|
92
143
|
// Handle port range object
|
|
93
144
|
const ports: number[] = [];
|
|
94
145
|
for (let p = item.from; p <= item.to; p++) {
|
|
@@ -99,14 +150,24 @@ export class RouteManager extends plugins.EventEmitter {
|
|
|
99
150
|
return [];
|
|
100
151
|
});
|
|
101
152
|
}
|
|
102
|
-
|
|
103
|
-
|
|
153
|
+
|
|
154
|
+
// Cache the result
|
|
155
|
+
this.portRangeCache.set(cacheKey, result);
|
|
156
|
+
|
|
157
|
+
return result;
|
|
104
158
|
}
|
|
105
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Memoization cache for expanded port ranges
|
|
162
|
+
*/
|
|
163
|
+
private portRangeCache: Map<string, number[]> = new Map();
|
|
164
|
+
|
|
106
165
|
/**
|
|
107
166
|
* Get all ports that should be listened on
|
|
167
|
+
* This method automatically infers all required ports from route configurations
|
|
108
168
|
*/
|
|
109
169
|
public getListeningPorts(): number[] {
|
|
170
|
+
// Return the unique set of ports from all routes
|
|
110
171
|
return Array.from(this.portMap.keys());
|
|
111
172
|
}
|
|
112
173
|
|
|
@@ -183,21 +244,36 @@ export class RouteManager extends plugins.EventEmitter {
|
|
|
183
244
|
* Match an IP against a pattern
|
|
184
245
|
*/
|
|
185
246
|
private matchIpPattern(pattern: string, ip: string): boolean {
|
|
186
|
-
//
|
|
187
|
-
|
|
247
|
+
// Normalize IPv6-mapped IPv4 addresses
|
|
248
|
+
const normalizedIp = ip.startsWith('::ffff:') ? ip.substring(7) : ip;
|
|
249
|
+
const normalizedPattern = pattern.startsWith('::ffff:') ? pattern.substring(7) : pattern;
|
|
250
|
+
|
|
251
|
+
// Handle exact match with normalized addresses
|
|
252
|
+
if (pattern === ip || normalizedPattern === normalizedIp ||
|
|
253
|
+
pattern === normalizedIp || normalizedPattern === ip) {
|
|
188
254
|
return true;
|
|
189
255
|
}
|
|
190
256
|
|
|
191
257
|
// Handle CIDR notation (e.g., 192.168.1.0/24)
|
|
192
258
|
if (pattern.includes('/')) {
|
|
193
|
-
return this.matchIpCidr(pattern,
|
|
259
|
+
return this.matchIpCidr(pattern, normalizedIp) ||
|
|
260
|
+
(normalizedPattern !== pattern && this.matchIpCidr(normalizedPattern, normalizedIp));
|
|
194
261
|
}
|
|
195
262
|
|
|
196
263
|
// Handle glob pattern (e.g., 192.168.1.*)
|
|
197
264
|
if (pattern.includes('*')) {
|
|
198
265
|
const regexPattern = pattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
|
|
199
266
|
const regex = new RegExp(`^${regexPattern}$`);
|
|
200
|
-
|
|
267
|
+
if (regex.test(ip) || regex.test(normalizedIp)) {
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// If pattern was normalized, also test with normalized pattern
|
|
272
|
+
if (normalizedPattern !== pattern) {
|
|
273
|
+
const normalizedRegexPattern = normalizedPattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
|
|
274
|
+
const normalizedRegex = new RegExp(`^${normalizedRegexPattern}$`);
|
|
275
|
+
return normalizedRegex.test(ip) || normalizedRegex.test(normalizedIp);
|
|
276
|
+
}
|
|
201
277
|
}
|
|
202
278
|
|
|
203
279
|
return false;
|
|
@@ -213,9 +289,13 @@ export class RouteManager extends plugins.EventEmitter {
|
|
|
213
289
|
const [subnet, bits] = cidr.split('/');
|
|
214
290
|
const mask = parseInt(bits, 10);
|
|
215
291
|
|
|
292
|
+
// Normalize IPv6-mapped IPv4 addresses
|
|
293
|
+
const normalizedIp = ip.startsWith('::ffff:') ? ip.substring(7) : ip;
|
|
294
|
+
const normalizedSubnet = subnet.startsWith('::ffff:') ? subnet.substring(7) : subnet;
|
|
295
|
+
|
|
216
296
|
// Convert IP addresses to numeric values
|
|
217
|
-
const ipNum = this.ipToNumber(
|
|
218
|
-
const subnetNum = this.ipToNumber(
|
|
297
|
+
const ipNum = this.ipToNumber(normalizedIp);
|
|
298
|
+
const subnetNum = this.ipToNumber(normalizedSubnet);
|
|
219
299
|
|
|
220
300
|
// Calculate subnet mask
|
|
221
301
|
const maskNum = ~(2 ** (32 - mask) - 1);
|
|
@@ -232,7 +312,10 @@ export class RouteManager extends plugins.EventEmitter {
|
|
|
232
312
|
* Convert an IP address to a numeric value
|
|
233
313
|
*/
|
|
234
314
|
private ipToNumber(ip: string): number {
|
|
235
|
-
|
|
315
|
+
// Normalize IPv6-mapped IPv4 addresses
|
|
316
|
+
const normalizedIp = ip.startsWith('::ffff:') ? ip.substring(7) : ip;
|
|
317
|
+
|
|
318
|
+
const parts = normalizedIp.split('.').map(part => parseInt(part, 10));
|
|
236
319
|
return (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3];
|
|
237
320
|
}
|
|
238
321
|
|
|
@@ -304,135 +387,9 @@ export class RouteManager extends plugins.EventEmitter {
|
|
|
304
387
|
}
|
|
305
388
|
|
|
306
389
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*/
|
|
310
|
-
public domainConfigToRoutes(domainConfig: IDomainConfig): IRouteConfig[] {
|
|
311
|
-
const routes: IRouteConfig[] = [];
|
|
312
|
-
const { domains, forwarding } = domainConfig;
|
|
313
|
-
|
|
314
|
-
// Determine the action based on forwarding type
|
|
315
|
-
let action: IRouteAction = {
|
|
316
|
-
type: 'forward',
|
|
317
|
-
target: {
|
|
318
|
-
host: forwarding.target.host,
|
|
319
|
-
port: forwarding.target.port
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
// Set TLS mode based on forwarding type
|
|
324
|
-
switch (forwarding.type) {
|
|
325
|
-
case 'http-only':
|
|
326
|
-
// No TLS settings needed
|
|
327
|
-
break;
|
|
328
|
-
case 'https-passthrough':
|
|
329
|
-
action.tls = { mode: 'passthrough' };
|
|
330
|
-
break;
|
|
331
|
-
case 'https-terminate-to-http':
|
|
332
|
-
action.tls = {
|
|
333
|
-
mode: 'terminate',
|
|
334
|
-
certificate: forwarding.https?.customCert ? {
|
|
335
|
-
key: forwarding.https.customCert.key,
|
|
336
|
-
cert: forwarding.https.customCert.cert
|
|
337
|
-
} : 'auto'
|
|
338
|
-
};
|
|
339
|
-
break;
|
|
340
|
-
case 'https-terminate-to-https':
|
|
341
|
-
action.tls = {
|
|
342
|
-
mode: 'terminate-and-reencrypt',
|
|
343
|
-
certificate: forwarding.https?.customCert ? {
|
|
344
|
-
key: forwarding.https.customCert.key,
|
|
345
|
-
cert: forwarding.https.customCert.cert
|
|
346
|
-
} : 'auto'
|
|
347
|
-
};
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// Add security settings if present
|
|
352
|
-
if (forwarding.security) {
|
|
353
|
-
action.security = {
|
|
354
|
-
allowedIps: forwarding.security.allowedIps,
|
|
355
|
-
blockedIps: forwarding.security.blockedIps,
|
|
356
|
-
maxConnections: forwarding.security.maxConnections
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// Add advanced settings if present
|
|
361
|
-
if (forwarding.advanced) {
|
|
362
|
-
action.advanced = {
|
|
363
|
-
timeout: forwarding.advanced.timeout,
|
|
364
|
-
headers: forwarding.advanced.headers,
|
|
365
|
-
keepAlive: forwarding.advanced.keepAlive
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// Determine which port to use based on forwarding type
|
|
370
|
-
const defaultPort = forwarding.type.startsWith('https') ? 443 : 80;
|
|
371
|
-
|
|
372
|
-
// Add the main route
|
|
373
|
-
routes.push({
|
|
374
|
-
match: {
|
|
375
|
-
ports: defaultPort,
|
|
376
|
-
domains
|
|
377
|
-
},
|
|
378
|
-
action,
|
|
379
|
-
name: `Route for ${domains.join(', ')}`
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
// Add HTTP redirect if needed
|
|
383
|
-
if (forwarding.http?.redirectToHttps) {
|
|
384
|
-
routes.push({
|
|
385
|
-
match: {
|
|
386
|
-
ports: 80,
|
|
387
|
-
domains
|
|
388
|
-
},
|
|
389
|
-
action: {
|
|
390
|
-
type: 'redirect',
|
|
391
|
-
redirect: {
|
|
392
|
-
to: 'https://{domain}{path}',
|
|
393
|
-
status: 301
|
|
394
|
-
}
|
|
395
|
-
},
|
|
396
|
-
name: `HTTP Redirect for ${domains.join(', ')}`,
|
|
397
|
-
priority: 100 // Higher priority for redirects
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// Add port ranges if specified
|
|
402
|
-
if (forwarding.advanced?.portRanges) {
|
|
403
|
-
for (const range of forwarding.advanced.portRanges) {
|
|
404
|
-
routes.push({
|
|
405
|
-
match: {
|
|
406
|
-
ports: [{ from: range.from, to: range.to }],
|
|
407
|
-
domains
|
|
408
|
-
},
|
|
409
|
-
action,
|
|
410
|
-
name: `Port Range ${range.from}-${range.to} for ${domains.join(', ')}`
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return routes;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Update routes based on domain configs
|
|
420
|
-
* (For backward compatibility with code that still uses domainConfigs)
|
|
390
|
+
* Domain-based configuration methods have been removed
|
|
391
|
+
* as part of the migration to pure route-based configuration
|
|
421
392
|
*/
|
|
422
|
-
public updateFromDomainConfigs(domainConfigs: IDomainConfig[]): void {
|
|
423
|
-
const routes: IRouteConfig[] = [];
|
|
424
|
-
|
|
425
|
-
// Convert each domain config to routes
|
|
426
|
-
for (const config of domainConfigs) {
|
|
427
|
-
routes.push(...this.domainConfigToRoutes(config));
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// Merge with existing routes that aren't derived from domain configs
|
|
431
|
-
const nonDomainRoutes = this.routes.filter(r =>
|
|
432
|
-
!r.name || !r.name.includes('for '));
|
|
433
|
-
|
|
434
|
-
this.updateRoutes([...nonDomainRoutes, ...routes]);
|
|
435
|
-
}
|
|
436
393
|
|
|
437
394
|
/**
|
|
438
395
|
* Validate the route configuration and return any warnings
|