@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
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
IRouteConfig,
|
|
3
|
-
IRouteMatch,
|
|
4
|
-
IRouteAction,
|
|
5
|
-
IRouteTarget,
|
|
6
|
-
IRouteTls,
|
|
7
|
-
IRouteRedirect,
|
|
8
|
-
IRouteSecurity,
|
|
9
|
-
IRouteAdvanced,
|
|
10
|
-
TPortRange
|
|
11
|
-
} from './models/route-types.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Basic helper function to create a route configuration
|
|
15
|
-
*/
|
|
16
|
-
export function createRoute(
|
|
17
|
-
match: IRouteMatch,
|
|
18
|
-
action: IRouteAction,
|
|
19
|
-
metadata?: {
|
|
20
|
-
name?: string;
|
|
21
|
-
description?: string;
|
|
22
|
-
priority?: number;
|
|
23
|
-
tags?: string[];
|
|
24
|
-
}
|
|
25
|
-
): IRouteConfig {
|
|
26
|
-
return {
|
|
27
|
-
match,
|
|
28
|
-
action,
|
|
29
|
-
...metadata
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Create a basic HTTP route configuration
|
|
35
|
-
*/
|
|
36
|
-
export function createHttpRoute(
|
|
37
|
-
options: {
|
|
38
|
-
ports?: number | number[]; // Default: 80
|
|
39
|
-
domains?: string | string[];
|
|
40
|
-
path?: string;
|
|
41
|
-
target: IRouteTarget;
|
|
42
|
-
headers?: Record<string, string>;
|
|
43
|
-
security?: IRouteSecurity;
|
|
44
|
-
name?: string;
|
|
45
|
-
description?: string;
|
|
46
|
-
priority?: number;
|
|
47
|
-
tags?: string[];
|
|
48
|
-
}
|
|
49
|
-
): IRouteConfig {
|
|
50
|
-
return createRoute(
|
|
51
|
-
{
|
|
52
|
-
ports: options.ports || 80,
|
|
53
|
-
...(options.domains ? { domains: options.domains } : {}),
|
|
54
|
-
...(options.path ? { path: options.path } : {})
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
type: 'forward',
|
|
58
|
-
target: options.target,
|
|
59
|
-
...(options.headers || options.security ? {
|
|
60
|
-
advanced: {
|
|
61
|
-
...(options.headers ? { headers: options.headers } : {})
|
|
62
|
-
},
|
|
63
|
-
...(options.security ? { security: options.security } : {})
|
|
64
|
-
} : {})
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: options.name || 'HTTP Route',
|
|
68
|
-
description: options.description,
|
|
69
|
-
priority: options.priority,
|
|
70
|
-
tags: options.tags
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Create an HTTPS route configuration with TLS termination
|
|
77
|
-
*/
|
|
78
|
-
export function createHttpsRoute(
|
|
79
|
-
options: {
|
|
80
|
-
ports?: number | number[]; // Default: 443
|
|
81
|
-
domains: string | string[];
|
|
82
|
-
path?: string;
|
|
83
|
-
target: IRouteTarget;
|
|
84
|
-
tlsMode?: 'terminate' | 'terminate-and-reencrypt';
|
|
85
|
-
certificate?: 'auto' | { key: string; cert: string };
|
|
86
|
-
headers?: Record<string, string>;
|
|
87
|
-
security?: IRouteSecurity;
|
|
88
|
-
name?: string;
|
|
89
|
-
description?: string;
|
|
90
|
-
priority?: number;
|
|
91
|
-
tags?: string[];
|
|
92
|
-
}
|
|
93
|
-
): IRouteConfig {
|
|
94
|
-
return createRoute(
|
|
95
|
-
{
|
|
96
|
-
ports: options.ports || 443,
|
|
97
|
-
domains: options.domains,
|
|
98
|
-
...(options.path ? { path: options.path } : {})
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
type: 'forward',
|
|
102
|
-
target: options.target,
|
|
103
|
-
tls: {
|
|
104
|
-
mode: options.tlsMode || 'terminate',
|
|
105
|
-
certificate: options.certificate || 'auto'
|
|
106
|
-
},
|
|
107
|
-
...(options.headers || options.security ? {
|
|
108
|
-
advanced: {
|
|
109
|
-
...(options.headers ? { headers: options.headers } : {})
|
|
110
|
-
},
|
|
111
|
-
...(options.security ? { security: options.security } : {})
|
|
112
|
-
} : {})
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: options.name || 'HTTPS Route',
|
|
116
|
-
description: options.description,
|
|
117
|
-
priority: options.priority,
|
|
118
|
-
tags: options.tags
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Create an HTTPS passthrough route configuration
|
|
125
|
-
*/
|
|
126
|
-
export function createPassthroughRoute(
|
|
127
|
-
options: {
|
|
128
|
-
ports?: number | number[]; // Default: 443
|
|
129
|
-
domains?: string | string[];
|
|
130
|
-
target: IRouteTarget;
|
|
131
|
-
security?: IRouteSecurity;
|
|
132
|
-
name?: string;
|
|
133
|
-
description?: string;
|
|
134
|
-
priority?: number;
|
|
135
|
-
tags?: string[];
|
|
136
|
-
}
|
|
137
|
-
): IRouteConfig {
|
|
138
|
-
return createRoute(
|
|
139
|
-
{
|
|
140
|
-
ports: options.ports || 443,
|
|
141
|
-
...(options.domains ? { domains: options.domains } : {})
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
type: 'forward',
|
|
145
|
-
target: options.target,
|
|
146
|
-
tls: {
|
|
147
|
-
mode: 'passthrough'
|
|
148
|
-
},
|
|
149
|
-
...(options.security ? { security: options.security } : {})
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
name: options.name || 'HTTPS Passthrough Route',
|
|
153
|
-
description: options.description,
|
|
154
|
-
priority: options.priority,
|
|
155
|
-
tags: options.tags
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Create a redirect route configuration
|
|
162
|
-
*/
|
|
163
|
-
export function createRedirectRoute(
|
|
164
|
-
options: {
|
|
165
|
-
ports?: number | number[]; // Default: 80
|
|
166
|
-
domains?: string | string[];
|
|
167
|
-
path?: string;
|
|
168
|
-
redirectTo: string;
|
|
169
|
-
statusCode?: 301 | 302 | 307 | 308;
|
|
170
|
-
name?: string;
|
|
171
|
-
description?: string;
|
|
172
|
-
priority?: number;
|
|
173
|
-
tags?: string[];
|
|
174
|
-
}
|
|
175
|
-
): IRouteConfig {
|
|
176
|
-
return createRoute(
|
|
177
|
-
{
|
|
178
|
-
ports: options.ports || 80,
|
|
179
|
-
...(options.domains ? { domains: options.domains } : {}),
|
|
180
|
-
...(options.path ? { path: options.path } : {})
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
type: 'redirect',
|
|
184
|
-
redirect: {
|
|
185
|
-
to: options.redirectTo,
|
|
186
|
-
status: options.statusCode || 301
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
name: options.name || 'Redirect Route',
|
|
191
|
-
description: options.description,
|
|
192
|
-
priority: options.priority,
|
|
193
|
-
tags: options.tags
|
|
194
|
-
}
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Create an HTTP to HTTPS redirect route configuration
|
|
200
|
-
*/
|
|
201
|
-
export function createHttpToHttpsRedirect(
|
|
202
|
-
options: {
|
|
203
|
-
domains: string | string[];
|
|
204
|
-
statusCode?: 301 | 302 | 307 | 308;
|
|
205
|
-
name?: string;
|
|
206
|
-
priority?: number;
|
|
207
|
-
}
|
|
208
|
-
): IRouteConfig {
|
|
209
|
-
const domainArray = Array.isArray(options.domains) ? options.domains : [options.domains];
|
|
210
|
-
|
|
211
|
-
return createRedirectRoute({
|
|
212
|
-
ports: 80,
|
|
213
|
-
domains: options.domains,
|
|
214
|
-
redirectTo: 'https://{domain}{path}',
|
|
215
|
-
statusCode: options.statusCode || 301,
|
|
216
|
-
name: options.name || `HTTP to HTTPS Redirect for ${domainArray.join(', ')}`,
|
|
217
|
-
priority: options.priority || 100 // High priority for redirects
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Create a block route configuration
|
|
223
|
-
*/
|
|
224
|
-
export function createBlockRoute(
|
|
225
|
-
options: {
|
|
226
|
-
ports: number | number[];
|
|
227
|
-
domains?: string | string[];
|
|
228
|
-
clientIp?: string[];
|
|
229
|
-
name?: string;
|
|
230
|
-
description?: string;
|
|
231
|
-
priority?: number;
|
|
232
|
-
tags?: string[];
|
|
233
|
-
}
|
|
234
|
-
): IRouteConfig {
|
|
235
|
-
return createRoute(
|
|
236
|
-
{
|
|
237
|
-
ports: options.ports,
|
|
238
|
-
...(options.domains ? { domains: options.domains } : {}),
|
|
239
|
-
...(options.clientIp ? { clientIp: options.clientIp } : {})
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
type: 'block'
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
name: options.name || 'Block Route',
|
|
246
|
-
description: options.description,
|
|
247
|
-
priority: options.priority || 1000, // Very high priority for blocks
|
|
248
|
-
tags: options.tags
|
|
249
|
-
}
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Create a load balancer route configuration
|
|
255
|
-
*/
|
|
256
|
-
export function createLoadBalancerRoute(
|
|
257
|
-
options: {
|
|
258
|
-
ports?: number | number[]; // Default: 443
|
|
259
|
-
domains: string | string[];
|
|
260
|
-
path?: string;
|
|
261
|
-
targets: string[]; // Array of host names/IPs for load balancing
|
|
262
|
-
targetPort: number;
|
|
263
|
-
tlsMode?: 'passthrough' | 'terminate' | 'terminate-and-reencrypt';
|
|
264
|
-
certificate?: 'auto' | { key: string; cert: string };
|
|
265
|
-
headers?: Record<string, string>;
|
|
266
|
-
security?: IRouteSecurity;
|
|
267
|
-
name?: string;
|
|
268
|
-
description?: string;
|
|
269
|
-
tags?: string[];
|
|
270
|
-
}
|
|
271
|
-
): IRouteConfig {
|
|
272
|
-
const useTls = options.tlsMode !== undefined;
|
|
273
|
-
const defaultPort = useTls ? 443 : 80;
|
|
274
|
-
|
|
275
|
-
return createRoute(
|
|
276
|
-
{
|
|
277
|
-
ports: options.ports || defaultPort,
|
|
278
|
-
domains: options.domains,
|
|
279
|
-
...(options.path ? { path: options.path } : {})
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
type: 'forward',
|
|
283
|
-
target: {
|
|
284
|
-
host: options.targets,
|
|
285
|
-
port: options.targetPort
|
|
286
|
-
},
|
|
287
|
-
...(useTls ? {
|
|
288
|
-
tls: {
|
|
289
|
-
mode: options.tlsMode!,
|
|
290
|
-
...(options.tlsMode !== 'passthrough' && options.certificate ? {
|
|
291
|
-
certificate: options.certificate
|
|
292
|
-
} : {})
|
|
293
|
-
}
|
|
294
|
-
} : {}),
|
|
295
|
-
...(options.headers || options.security ? {
|
|
296
|
-
advanced: {
|
|
297
|
-
...(options.headers ? { headers: options.headers } : {})
|
|
298
|
-
},
|
|
299
|
-
...(options.security ? { security: options.security } : {})
|
|
300
|
-
} : {})
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
name: options.name || 'Load Balanced Route',
|
|
304
|
-
description: options.description || `Load balancing across ${options.targets.length} backends`,
|
|
305
|
-
tags: options.tags
|
|
306
|
-
}
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Create a complete HTTPS server configuration with HTTP redirect
|
|
312
|
-
*/
|
|
313
|
-
export function createHttpsServer(
|
|
314
|
-
options: {
|
|
315
|
-
domains: string | string[];
|
|
316
|
-
target: IRouteTarget;
|
|
317
|
-
certificate?: 'auto' | { key: string; cert: string };
|
|
318
|
-
security?: IRouteSecurity;
|
|
319
|
-
addHttpRedirect?: boolean;
|
|
320
|
-
name?: string;
|
|
321
|
-
}
|
|
322
|
-
): IRouteConfig[] {
|
|
323
|
-
const routes: IRouteConfig[] = [];
|
|
324
|
-
const domainArray = Array.isArray(options.domains) ? options.domains : [options.domains];
|
|
325
|
-
|
|
326
|
-
// Add HTTPS route
|
|
327
|
-
routes.push(createHttpsRoute({
|
|
328
|
-
domains: options.domains,
|
|
329
|
-
target: options.target,
|
|
330
|
-
certificate: options.certificate || 'auto',
|
|
331
|
-
security: options.security,
|
|
332
|
-
name: options.name || `HTTPS Server for ${domainArray.join(', ')}`
|
|
333
|
-
}));
|
|
334
|
-
|
|
335
|
-
// Add HTTP to HTTPS redirect if requested
|
|
336
|
-
if (options.addHttpRedirect !== false) {
|
|
337
|
-
routes.push(createHttpToHttpsRedirect({
|
|
338
|
-
domains: options.domains,
|
|
339
|
-
name: `HTTP to HTTPS Redirect for ${domainArray.join(', ')}`,
|
|
340
|
-
priority: 100
|
|
341
|
-
}));
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return routes;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Create a port range configuration from various input formats
|
|
349
|
-
*/
|
|
350
|
-
export function createPortRange(
|
|
351
|
-
ports: number | number[] | string | Array<{ from: number; to: number }>
|
|
352
|
-
): TPortRange {
|
|
353
|
-
// If it's a string like "80,443" or "8000-9000", parse it
|
|
354
|
-
if (typeof ports === 'string') {
|
|
355
|
-
if (ports.includes('-')) {
|
|
356
|
-
// Handle range like "8000-9000"
|
|
357
|
-
const [start, end] = ports.split('-').map(p => parseInt(p.trim(), 10));
|
|
358
|
-
return [{ from: start, to: end }];
|
|
359
|
-
} else if (ports.includes(',')) {
|
|
360
|
-
// Handle comma-separated list like "80,443,8080"
|
|
361
|
-
return ports.split(',').map(p => parseInt(p.trim(), 10));
|
|
362
|
-
} else {
|
|
363
|
-
// Handle single port as string
|
|
364
|
-
return parseInt(ports.trim(), 10);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// Otherwise return as is
|
|
369
|
-
return ports;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Create a security configuration object
|
|
374
|
-
*/
|
|
375
|
-
export function createSecurityConfig(
|
|
376
|
-
options: {
|
|
377
|
-
allowedIps?: string[];
|
|
378
|
-
blockedIps?: string[];
|
|
379
|
-
maxConnections?: number;
|
|
380
|
-
authentication?: {
|
|
381
|
-
type: 'basic' | 'digest' | 'oauth';
|
|
382
|
-
// Auth-specific options
|
|
383
|
-
[key: string]: any;
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
): IRouteSecurity {
|
|
387
|
-
return {
|
|
388
|
-
...(options.allowedIps ? { allowedIps: options.allowedIps } : {}),
|
|
389
|
-
...(options.blockedIps ? { blockedIps: options.blockedIps } : {}),
|
|
390
|
-
...(options.maxConnections ? { maxConnections: options.maxConnections } : {}),
|
|
391
|
-
...(options.authentication ? { authentication: options.authentication } : {})
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Create a static file server route
|
|
397
|
-
*/
|
|
398
|
-
export function createStaticFileRoute(
|
|
399
|
-
options: {
|
|
400
|
-
ports?: number | number[]; // Default: 80
|
|
401
|
-
domains: string | string[];
|
|
402
|
-
path?: string;
|
|
403
|
-
targetDirectory: string;
|
|
404
|
-
tlsMode?: 'terminate' | 'terminate-and-reencrypt';
|
|
405
|
-
certificate?: 'auto' | { key: string; cert: string };
|
|
406
|
-
headers?: Record<string, string>;
|
|
407
|
-
security?: IRouteSecurity;
|
|
408
|
-
name?: string;
|
|
409
|
-
description?: string;
|
|
410
|
-
priority?: number;
|
|
411
|
-
tags?: string[];
|
|
412
|
-
}
|
|
413
|
-
): IRouteConfig {
|
|
414
|
-
const useTls = options.tlsMode !== undefined;
|
|
415
|
-
const defaultPort = useTls ? 443 : 80;
|
|
416
|
-
|
|
417
|
-
return createRoute(
|
|
418
|
-
{
|
|
419
|
-
ports: options.ports || defaultPort,
|
|
420
|
-
domains: options.domains,
|
|
421
|
-
...(options.path ? { path: options.path } : {})
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
type: 'forward',
|
|
425
|
-
target: {
|
|
426
|
-
host: 'localhost', // Static file serving is typically handled locally
|
|
427
|
-
port: 0, // Special value indicating a static file server
|
|
428
|
-
preservePort: false
|
|
429
|
-
},
|
|
430
|
-
...(useTls ? {
|
|
431
|
-
tls: {
|
|
432
|
-
mode: options.tlsMode!,
|
|
433
|
-
certificate: options.certificate || 'auto'
|
|
434
|
-
}
|
|
435
|
-
} : {}),
|
|
436
|
-
advanced: {
|
|
437
|
-
...(options.headers ? { headers: options.headers } : {}),
|
|
438
|
-
staticFiles: {
|
|
439
|
-
root: options.targetDirectory,
|
|
440
|
-
index: ['index.html', 'index.htm'],
|
|
441
|
-
directory: options.targetDirectory // For backward compatibility
|
|
442
|
-
}
|
|
443
|
-
},
|
|
444
|
-
...(options.security ? { security: options.security } : {})
|
|
445
|
-
},
|
|
446
|
-
{
|
|
447
|
-
name: options.name || 'Static File Server',
|
|
448
|
-
description: options.description || `Serving static files from ${options.targetDirectory}`,
|
|
449
|
-
priority: options.priority,
|
|
450
|
-
tags: options.tags
|
|
451
|
-
}
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Create a test route for debugging purposes
|
|
457
|
-
*/
|
|
458
|
-
export function createTestRoute(
|
|
459
|
-
options: {
|
|
460
|
-
ports?: number | number[]; // Default: 8000
|
|
461
|
-
domains?: string | string[];
|
|
462
|
-
path?: string;
|
|
463
|
-
response?: {
|
|
464
|
-
status?: number;
|
|
465
|
-
headers?: Record<string, string>;
|
|
466
|
-
body?: string;
|
|
467
|
-
};
|
|
468
|
-
name?: string;
|
|
469
|
-
}
|
|
470
|
-
): IRouteConfig {
|
|
471
|
-
return createRoute(
|
|
472
|
-
{
|
|
473
|
-
ports: options.ports || 8000,
|
|
474
|
-
...(options.domains ? { domains: options.domains } : {}),
|
|
475
|
-
...(options.path ? { path: options.path } : {})
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
type: 'forward',
|
|
479
|
-
target: {
|
|
480
|
-
host: 'test', // Special value indicating a test route
|
|
481
|
-
port: 0
|
|
482
|
-
},
|
|
483
|
-
advanced: {
|
|
484
|
-
testResponse: {
|
|
485
|
-
status: options.response?.status || 200,
|
|
486
|
-
headers: options.response?.headers || { 'Content-Type': 'text/plain' },
|
|
487
|
-
body: options.response?.body || 'Test route is working!'
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
},
|
|
491
|
-
{
|
|
492
|
-
name: options.name || 'Test Route',
|
|
493
|
-
description: 'Route for testing and debugging',
|
|
494
|
-
priority: 500,
|
|
495
|
-
tags: ['test', 'debug']
|
|
496
|
-
}
|
|
497
|
-
);
|
|
498
|
-
}
|