@push.rocks/smartproxy 20.0.1 → 21.1.0
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/changelog.md +26 -0
- package/dist_ts/core/utils/proxy-protocol.d.ts +5 -17
- package/dist_ts/core/utils/proxy-protocol.js +13 -97
- package/dist_ts/core/utils/websocket-utils.d.ts +6 -7
- package/dist_ts/core/utils/websocket-utils.js +10 -66
- package/dist_ts/detection/detectors/http-detector-v2.d.ts +33 -0
- package/dist_ts/detection/detectors/http-detector-v2.js +87 -0
- package/dist_ts/detection/detectors/http-detector.d.ts +33 -0
- package/dist_ts/detection/detectors/http-detector.js +89 -0
- package/dist_ts/detection/detectors/quick-detector.d.ts +28 -0
- package/dist_ts/detection/detectors/quick-detector.js +131 -0
- package/dist_ts/detection/detectors/routing-extractor.d.ts +28 -0
- package/dist_ts/detection/detectors/routing-extractor.js +122 -0
- package/dist_ts/detection/detectors/tls-detector-v2.d.ts +33 -0
- package/dist_ts/detection/detectors/tls-detector-v2.js +80 -0
- package/dist_ts/detection/detectors/tls-detector.d.ts +33 -0
- package/dist_ts/detection/detectors/tls-detector.js +106 -0
- package/dist_ts/detection/index.d.ts +17 -0
- package/dist_ts/detection/index.js +22 -0
- package/dist_ts/detection/models/detection-types.d.ts +87 -0
- package/dist_ts/detection/models/detection-types.js +5 -0
- package/dist_ts/detection/models/interfaces.d.ts +97 -0
- package/dist_ts/detection/models/interfaces.js +5 -0
- package/dist_ts/detection/protocol-detector-v2.d.ts +46 -0
- package/dist_ts/detection/protocol-detector-v2.js +116 -0
- package/dist_ts/detection/protocol-detector.d.ts +74 -0
- package/dist_ts/detection/protocol-detector.js +173 -0
- package/dist_ts/detection/utils/buffer-utils.d.ts +61 -0
- package/dist_ts/detection/utils/buffer-utils.js +127 -0
- package/dist_ts/detection/utils/fragment-manager.d.ts +31 -0
- package/dist_ts/detection/utils/fragment-manager.js +53 -0
- package/dist_ts/detection/utils/parser-utils.d.ts +42 -0
- package/dist_ts/detection/utils/parser-utils.js +63 -0
- package/dist_ts/index.d.ts +2 -1
- package/dist_ts/index.js +3 -2
- package/dist_ts/protocols/common/fragment-handler.d.ts +73 -0
- package/dist_ts/protocols/common/fragment-handler.js +117 -0
- package/dist_ts/protocols/common/index.d.ts +7 -0
- package/dist_ts/protocols/common/index.js +8 -0
- package/dist_ts/protocols/common/types.d.ts +68 -0
- package/dist_ts/protocols/common/types.js +7 -0
- package/dist_ts/protocols/http/constants.d.ts +119 -0
- package/dist_ts/protocols/http/constants.js +200 -0
- package/dist_ts/protocols/http/index.d.ts +7 -0
- package/dist_ts/protocols/http/index.js +8 -0
- package/dist_ts/protocols/http/parser.d.ts +58 -0
- package/dist_ts/protocols/http/parser.js +184 -0
- package/dist_ts/protocols/http/types.d.ts +62 -0
- package/dist_ts/protocols/http/types.js +5 -0
- package/dist_ts/protocols/index.d.ts +11 -0
- package/dist_ts/protocols/index.js +12 -0
- package/dist_ts/protocols/proxy/index.d.ts +6 -0
- package/dist_ts/protocols/proxy/index.js +7 -0
- package/dist_ts/protocols/proxy/parser.d.ts +44 -0
- package/dist_ts/protocols/proxy/parser.js +153 -0
- package/dist_ts/protocols/proxy/types.d.ts +47 -0
- package/dist_ts/protocols/proxy/types.js +6 -0
- package/dist_ts/protocols/tls/alerts/index.d.ts +4 -0
- package/dist_ts/protocols/tls/alerts/index.js +5 -0
- package/dist_ts/protocols/tls/alerts/tls-alert.d.ts +150 -0
- package/dist_ts/protocols/tls/alerts/tls-alert.js +226 -0
- package/dist_ts/protocols/tls/constants.d.ts +122 -0
- package/dist_ts/protocols/tls/constants.js +135 -0
- package/dist_ts/protocols/tls/index.d.ts +12 -0
- package/dist_ts/protocols/tls/index.js +27 -0
- package/dist_ts/protocols/tls/parser.d.ts +53 -0
- package/dist_ts/protocols/tls/parser.js +294 -0
- package/dist_ts/protocols/tls/sni/client-hello-parser.d.ts +100 -0
- package/dist_ts/protocols/tls/sni/client-hello-parser.js +463 -0
- package/dist_ts/protocols/tls/sni/index.d.ts +5 -0
- package/dist_ts/protocols/tls/sni/index.js +6 -0
- package/dist_ts/protocols/tls/sni/sni-extraction.d.ts +58 -0
- package/dist_ts/protocols/tls/sni/sni-extraction.js +275 -0
- package/dist_ts/protocols/tls/types.d.ts +65 -0
- package/dist_ts/protocols/tls/types.js +5 -0
- package/dist_ts/protocols/tls/utils/index.d.ts +4 -0
- package/dist_ts/protocols/tls/utils/index.js +5 -0
- package/dist_ts/protocols/tls/utils/tls-utils.d.ts +158 -0
- package/dist_ts/protocols/tls/utils/tls-utils.js +187 -0
- package/dist_ts/protocols/websocket/constants.d.ts +55 -0
- package/dist_ts/protocols/websocket/constants.js +58 -0
- package/dist_ts/protocols/websocket/index.d.ts +7 -0
- package/dist_ts/protocols/websocket/index.js +8 -0
- package/dist_ts/protocols/websocket/types.d.ts +47 -0
- package/dist_ts/protocols/websocket/types.js +5 -0
- package/dist_ts/protocols/websocket/utils.d.ts +25 -0
- package/dist_ts/protocols/websocket/utils.js +103 -0
- package/dist_ts/proxies/http-proxy/models/http-types.d.ts +25 -27
- package/dist_ts/proxies/http-proxy/models/http-types.js +24 -44
- package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -0
- package/dist_ts/proxies/smart-proxy/models/route-types.js +1 -1
- package/dist_ts/proxies/smart-proxy/route-connection-handler.js +81 -61
- package/dist_ts/proxies/smart-proxy/tls-manager.js +2 -1
- package/dist_ts/proxies/smart-proxy/utils/index.d.ts +1 -2
- package/dist_ts/proxies/smart-proxy/utils/index.js +3 -4
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +112 -8
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +231 -76
- package/dist_ts/tls/index.d.ts +5 -7
- package/dist_ts/tls/index.js +8 -11
- package/dist_ts/tls/sni/client-hello-parser.js +3 -2
- package/dist_ts/tls/sni/sni-handler.js +4 -4
- package/dist_ts/tls/utils/tls-utils.d.ts +1 -110
- package/dist_ts/tls/utils/tls-utils.js +4 -116
- package/package.json +17 -8
- package/readme.md +471 -2345
- package/readme.plan.md +0 -0
- package/ts/core/utils/proxy-protocol.ts +14 -131
- package/ts/core/utils/websocket-utils.ts +12 -60
- package/ts/detection/detectors/http-detector.ts +114 -0
- package/ts/detection/detectors/quick-detector.ts +148 -0
- package/ts/detection/detectors/routing-extractor.ts +147 -0
- package/ts/detection/detectors/tls-detector.ts +120 -0
- package/ts/detection/index.ts +25 -0
- package/ts/detection/models/detection-types.ts +102 -0
- package/ts/detection/models/interfaces.ts +115 -0
- package/ts/detection/protocol-detector.ts +230 -0
- package/ts/detection/utils/buffer-utils.ts +141 -0
- package/ts/detection/utils/fragment-manager.ts +64 -0
- package/ts/detection/utils/parser-utils.ts +77 -0
- package/ts/index.ts +3 -2
- package/ts/protocols/common/fragment-handler.ts +163 -0
- package/ts/protocols/common/index.ts +8 -0
- package/ts/protocols/common/types.ts +76 -0
- package/ts/protocols/http/constants.ts +219 -0
- package/ts/protocols/http/index.ts +8 -0
- package/ts/protocols/http/parser.ts +219 -0
- package/ts/protocols/http/types.ts +70 -0
- package/ts/protocols/index.ts +12 -0
- package/ts/protocols/proxy/index.ts +7 -0
- package/ts/protocols/proxy/parser.ts +183 -0
- package/ts/protocols/proxy/types.ts +53 -0
- package/ts/{tls → protocols/tls}/alerts/tls-alert.ts +1 -1
- package/ts/protocols/tls/index.ts +37 -0
- package/ts/protocols/tls/sni/index.ts +6 -0
- package/ts/{tls → protocols/tls}/utils/tls-utils.ts +1 -1
- package/ts/protocols/websocket/constants.ts +60 -0
- package/ts/protocols/websocket/index.ts +8 -0
- package/ts/protocols/websocket/types.ts +53 -0
- package/ts/protocols/websocket/utils.ts +98 -0
- package/ts/proxies/http-proxy/models/http-types.ts +29 -46
- package/ts/proxies/smart-proxy/models/interfaces.ts +7 -1
- package/ts/proxies/smart-proxy/models/route-types.ts +0 -1
- package/ts/proxies/smart-proxy/route-connection-handler.ts +91 -68
- package/ts/proxies/smart-proxy/tls-manager.ts +1 -0
- package/ts/proxies/smart-proxy/utils/index.ts +2 -13
- package/ts/proxies/smart-proxy/utils/route-helpers.ts +323 -86
- package/ts/tls/index.ts +8 -12
- package/ts/tls/sni/sni-handler.ts +3 -3
- package/ts/forwarding/config/forwarding-types.ts +0 -76
- package/ts/forwarding/config/index.ts +0 -26
- package/ts/forwarding/factory/forwarding-factory.ts +0 -189
- package/ts/forwarding/factory/index.ts +0 -5
- package/ts/forwarding/handlers/base-handler.ts +0 -155
- package/ts/forwarding/handlers/http-handler.ts +0 -163
- package/ts/forwarding/handlers/https-passthrough-handler.ts +0 -185
- package/ts/forwarding/handlers/https-terminate-to-http-handler.ts +0 -312
- package/ts/forwarding/handlers/https-terminate-to-https-handler.ts +0 -297
- package/ts/forwarding/handlers/index.ts +0 -9
- package/ts/forwarding/index.ts +0 -35
- package/ts/proxies/smart-proxy/utils/route-patterns.ts +0 -403
- /package/ts/{tls → protocols/tls}/alerts/index.ts +0 -0
- /package/ts/{tls → protocols/tls}/sni/client-hello-parser.ts +0 -0
- /package/ts/{tls → protocols/tls}/sni/sni-extraction.ts +0 -0
- /package/ts/{tls → protocols/tls}/utils/index.ts +0 -0
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route Patterns
|
|
3
|
-
*
|
|
4
|
-
* This file provides pre-defined route patterns for common use cases.
|
|
5
|
-
* These patterns can be used as templates for creating route configurations.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { IRouteConfig, IRouteMatch, IRouteAction, IRouteTarget } from '../models/route-types.js';
|
|
9
|
-
import { mergeRouteConfigs } from './route-utils.js';
|
|
10
|
-
import { SocketHandlers } from './route-helpers.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Create a basic HTTP route configuration
|
|
14
|
-
*/
|
|
15
|
-
export function createHttpRoute(
|
|
16
|
-
domains: string | string[],
|
|
17
|
-
target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number) },
|
|
18
|
-
options: Partial<IRouteConfig> = {}
|
|
19
|
-
): IRouteConfig {
|
|
20
|
-
const route: IRouteConfig = {
|
|
21
|
-
match: {
|
|
22
|
-
domains,
|
|
23
|
-
ports: 80
|
|
24
|
-
},
|
|
25
|
-
action: {
|
|
26
|
-
type: 'forward',
|
|
27
|
-
targets: [{
|
|
28
|
-
host: target.host,
|
|
29
|
-
port: target.port
|
|
30
|
-
}]
|
|
31
|
-
},
|
|
32
|
-
name: options.name || `HTTP: ${Array.isArray(domains) ? domains.join(', ') : domains}`
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return mergeRouteConfigs(route, options);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Create an HTTPS route with TLS termination
|
|
40
|
-
*/
|
|
41
|
-
export function createHttpsTerminateRoute(
|
|
42
|
-
domains: string | string[],
|
|
43
|
-
target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number) },
|
|
44
|
-
options: Partial<IRouteConfig> & {
|
|
45
|
-
certificate?: 'auto' | { key: string; cert: string };
|
|
46
|
-
reencrypt?: boolean;
|
|
47
|
-
} = {}
|
|
48
|
-
): IRouteConfig {
|
|
49
|
-
const route: IRouteConfig = {
|
|
50
|
-
match: {
|
|
51
|
-
domains,
|
|
52
|
-
ports: 443
|
|
53
|
-
},
|
|
54
|
-
action: {
|
|
55
|
-
type: 'forward',
|
|
56
|
-
targets: [{
|
|
57
|
-
host: target.host,
|
|
58
|
-
port: target.port
|
|
59
|
-
}],
|
|
60
|
-
tls: {
|
|
61
|
-
mode: options.reencrypt ? 'terminate-and-reencrypt' : 'terminate',
|
|
62
|
-
certificate: options.certificate || 'auto'
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
name: options.name || `HTTPS (terminate): ${Array.isArray(domains) ? domains.join(', ') : domains}`
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
return mergeRouteConfigs(route, options);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Create an HTTPS route with TLS passthrough
|
|
73
|
-
*/
|
|
74
|
-
export function createHttpsPassthroughRoute(
|
|
75
|
-
domains: string | string[],
|
|
76
|
-
target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number) },
|
|
77
|
-
options: Partial<IRouteConfig> = {}
|
|
78
|
-
): IRouteConfig {
|
|
79
|
-
const route: IRouteConfig = {
|
|
80
|
-
match: {
|
|
81
|
-
domains,
|
|
82
|
-
ports: 443
|
|
83
|
-
},
|
|
84
|
-
action: {
|
|
85
|
-
type: 'forward',
|
|
86
|
-
targets: [{
|
|
87
|
-
host: target.host,
|
|
88
|
-
port: target.port
|
|
89
|
-
}],
|
|
90
|
-
tls: {
|
|
91
|
-
mode: 'passthrough'
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
name: options.name || `HTTPS (passthrough): ${Array.isArray(domains) ? domains.join(', ') : domains}`
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
return mergeRouteConfigs(route, options);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Create an HTTP to HTTPS redirect route
|
|
102
|
-
*/
|
|
103
|
-
export function createHttpToHttpsRedirect(
|
|
104
|
-
domains: string | string[],
|
|
105
|
-
options: Partial<IRouteConfig> & {
|
|
106
|
-
redirectCode?: 301 | 302 | 307 | 308;
|
|
107
|
-
preservePath?: boolean;
|
|
108
|
-
} = {}
|
|
109
|
-
): IRouteConfig {
|
|
110
|
-
const route: IRouteConfig = {
|
|
111
|
-
match: {
|
|
112
|
-
domains,
|
|
113
|
-
ports: 80
|
|
114
|
-
},
|
|
115
|
-
action: {
|
|
116
|
-
type: 'socket-handler',
|
|
117
|
-
socketHandler: SocketHandlers.httpRedirect(
|
|
118
|
-
options.preservePath ? 'https://{domain}{path}' : 'https://{domain}',
|
|
119
|
-
options.redirectCode || 301
|
|
120
|
-
)
|
|
121
|
-
},
|
|
122
|
-
name: options.name || `HTTP to HTTPS redirect: ${Array.isArray(domains) ? domains.join(', ') : domains}`
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
return mergeRouteConfigs(route, options);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Create a complete HTTPS server with redirect from HTTP
|
|
130
|
-
*/
|
|
131
|
-
export function createCompleteHttpsServer(
|
|
132
|
-
domains: string | string[],
|
|
133
|
-
target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number) },
|
|
134
|
-
options: Partial<IRouteConfig> & {
|
|
135
|
-
certificate?: 'auto' | { key: string; cert: string };
|
|
136
|
-
tlsMode?: 'terminate' | 'passthrough' | 'terminate-and-reencrypt';
|
|
137
|
-
redirectCode?: 301 | 302 | 307 | 308;
|
|
138
|
-
} = {}
|
|
139
|
-
): IRouteConfig[] {
|
|
140
|
-
// Create the TLS route based on the selected mode
|
|
141
|
-
const tlsRoute = options.tlsMode === 'passthrough'
|
|
142
|
-
? createHttpsPassthroughRoute(domains, target, options)
|
|
143
|
-
: createHttpsTerminateRoute(domains, target, {
|
|
144
|
-
...options,
|
|
145
|
-
reencrypt: options.tlsMode === 'terminate-and-reencrypt'
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Create the HTTP to HTTPS redirect route
|
|
149
|
-
const redirectRoute = createHttpToHttpsRedirect(domains, {
|
|
150
|
-
redirectCode: options.redirectCode,
|
|
151
|
-
preservePath: true
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
return [tlsRoute, redirectRoute];
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Create an API Gateway route pattern
|
|
159
|
-
* @param domains Domain(s) to match
|
|
160
|
-
* @param apiBasePath Base path for API endpoints (e.g., '/api')
|
|
161
|
-
* @param target Target host and port
|
|
162
|
-
* @param options Additional route options
|
|
163
|
-
* @returns API route configuration
|
|
164
|
-
*/
|
|
165
|
-
export function createApiGatewayRoute(
|
|
166
|
-
domains: string | string[],
|
|
167
|
-
apiBasePath: string,
|
|
168
|
-
target: { host: string | string[]; port: number },
|
|
169
|
-
options: {
|
|
170
|
-
useTls?: boolean;
|
|
171
|
-
certificate?: 'auto' | { key: string; cert: string };
|
|
172
|
-
addCorsHeaders?: boolean;
|
|
173
|
-
[key: string]: any;
|
|
174
|
-
} = {}
|
|
175
|
-
): IRouteConfig {
|
|
176
|
-
// Normalize apiBasePath to ensure it starts with / and doesn't end with /
|
|
177
|
-
const normalizedPath = apiBasePath.startsWith('/')
|
|
178
|
-
? apiBasePath
|
|
179
|
-
: `/${apiBasePath}`;
|
|
180
|
-
|
|
181
|
-
// Add wildcard to path to match all API endpoints
|
|
182
|
-
const apiPath = normalizedPath.endsWith('/')
|
|
183
|
-
? `${normalizedPath}*`
|
|
184
|
-
: `${normalizedPath}/*`;
|
|
185
|
-
|
|
186
|
-
// Create base route
|
|
187
|
-
const baseRoute = options.useTls
|
|
188
|
-
? createHttpsTerminateRoute(domains, target, {
|
|
189
|
-
certificate: options.certificate || 'auto'
|
|
190
|
-
})
|
|
191
|
-
: createHttpRoute(domains, target);
|
|
192
|
-
|
|
193
|
-
// Add API-specific configurations
|
|
194
|
-
const apiRoute: Partial<IRouteConfig> = {
|
|
195
|
-
match: {
|
|
196
|
-
...baseRoute.match,
|
|
197
|
-
path: apiPath
|
|
198
|
-
},
|
|
199
|
-
name: options.name || `API Gateway: ${apiPath} -> ${Array.isArray(target.host) ? target.host.join(', ') : target.host}:${target.port}`,
|
|
200
|
-
priority: options.priority || 100 // Higher priority for specific path matching
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
// Add CORS headers if requested
|
|
204
|
-
if (options.addCorsHeaders) {
|
|
205
|
-
apiRoute.headers = {
|
|
206
|
-
response: {
|
|
207
|
-
'Access-Control-Allow-Origin': '*',
|
|
208
|
-
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
|
209
|
-
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
|
210
|
-
'Access-Control-Max-Age': '86400'
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return mergeRouteConfigs(baseRoute, apiRoute);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Create a WebSocket route pattern
|
|
220
|
-
* @param domains Domain(s) to match
|
|
221
|
-
* @param target WebSocket server host and port
|
|
222
|
-
* @param options Additional route options
|
|
223
|
-
* @returns WebSocket route configuration
|
|
224
|
-
*/
|
|
225
|
-
export function createWebSocketRoute(
|
|
226
|
-
domains: string | string[],
|
|
227
|
-
target: { host: string | string[]; port: number },
|
|
228
|
-
options: {
|
|
229
|
-
useTls?: boolean;
|
|
230
|
-
certificate?: 'auto' | { key: string; cert: string };
|
|
231
|
-
path?: string;
|
|
232
|
-
[key: string]: any;
|
|
233
|
-
} = {}
|
|
234
|
-
): IRouteConfig {
|
|
235
|
-
// Create base route
|
|
236
|
-
const baseRoute = options.useTls
|
|
237
|
-
? createHttpsTerminateRoute(domains, target, {
|
|
238
|
-
certificate: options.certificate || 'auto'
|
|
239
|
-
})
|
|
240
|
-
: createHttpRoute(domains, target);
|
|
241
|
-
|
|
242
|
-
// Add WebSocket-specific configurations
|
|
243
|
-
const wsRoute: Partial<IRouteConfig> = {
|
|
244
|
-
match: {
|
|
245
|
-
...baseRoute.match,
|
|
246
|
-
path: options.path || '/ws',
|
|
247
|
-
headers: {
|
|
248
|
-
'Upgrade': 'websocket'
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
action: {
|
|
252
|
-
...baseRoute.action,
|
|
253
|
-
websocket: {
|
|
254
|
-
enabled: true,
|
|
255
|
-
pingInterval: options.pingInterval || 30000, // 30 seconds
|
|
256
|
-
pingTimeout: options.pingTimeout || 5000 // 5 seconds
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
name: options.name || `WebSocket: ${Array.isArray(domains) ? domains.join(', ') : domains} -> ${Array.isArray(target.host) ? target.host.join(', ') : target.host}:${target.port}`,
|
|
260
|
-
priority: options.priority || 100 // Higher priority for WebSocket routes
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
return mergeRouteConfigs(baseRoute, wsRoute);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Create a load balancer route pattern
|
|
268
|
-
* @param domains Domain(s) to match
|
|
269
|
-
* @param backends Array of backend servers
|
|
270
|
-
* @param options Additional route options
|
|
271
|
-
* @returns Load balancer route configuration
|
|
272
|
-
*/
|
|
273
|
-
export function createLoadBalancerRoute(
|
|
274
|
-
domains: string | string[],
|
|
275
|
-
backends: Array<{ host: string; port: number }>,
|
|
276
|
-
options: {
|
|
277
|
-
useTls?: boolean;
|
|
278
|
-
certificate?: 'auto' | { key: string; cert: string };
|
|
279
|
-
algorithm?: 'round-robin' | 'least-connections' | 'ip-hash';
|
|
280
|
-
healthCheck?: {
|
|
281
|
-
path: string;
|
|
282
|
-
interval: number;
|
|
283
|
-
timeout: number;
|
|
284
|
-
unhealthyThreshold: number;
|
|
285
|
-
healthyThreshold: number;
|
|
286
|
-
};
|
|
287
|
-
[key: string]: any;
|
|
288
|
-
} = {}
|
|
289
|
-
): IRouteConfig {
|
|
290
|
-
// Extract hosts and ensure all backends use the same port
|
|
291
|
-
const port = backends[0].port;
|
|
292
|
-
const hosts = backends.map(backend => backend.host);
|
|
293
|
-
|
|
294
|
-
// Create route with multiple hosts for load balancing
|
|
295
|
-
const baseRoute = options.useTls
|
|
296
|
-
? createHttpsTerminateRoute(domains, { host: hosts, port }, {
|
|
297
|
-
certificate: options.certificate || 'auto'
|
|
298
|
-
})
|
|
299
|
-
: createHttpRoute(domains, { host: hosts, port });
|
|
300
|
-
|
|
301
|
-
// Add load balancing specific configurations
|
|
302
|
-
const lbRoute: Partial<IRouteConfig> = {
|
|
303
|
-
action: {
|
|
304
|
-
...baseRoute.action,
|
|
305
|
-
loadBalancing: {
|
|
306
|
-
algorithm: options.algorithm || 'round-robin',
|
|
307
|
-
healthCheck: options.healthCheck
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
name: options.name || `Load Balancer: ${Array.isArray(domains) ? domains.join(', ') : domains}`,
|
|
311
|
-
priority: options.priority || 50
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
return mergeRouteConfigs(baseRoute, lbRoute);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Create a rate limiting route pattern
|
|
319
|
-
* @param baseRoute Base route to add rate limiting to
|
|
320
|
-
* @param rateLimit Rate limiting configuration
|
|
321
|
-
* @returns Route with rate limiting
|
|
322
|
-
*/
|
|
323
|
-
export function addRateLimiting(
|
|
324
|
-
baseRoute: IRouteConfig,
|
|
325
|
-
rateLimit: {
|
|
326
|
-
maxRequests: number;
|
|
327
|
-
window: number; // Time window in seconds
|
|
328
|
-
keyBy?: 'ip' | 'path' | 'header';
|
|
329
|
-
headerName?: string; // Required if keyBy is 'header'
|
|
330
|
-
errorMessage?: string;
|
|
331
|
-
}
|
|
332
|
-
): IRouteConfig {
|
|
333
|
-
return mergeRouteConfigs(baseRoute, {
|
|
334
|
-
security: {
|
|
335
|
-
rateLimit: {
|
|
336
|
-
enabled: true,
|
|
337
|
-
maxRequests: rateLimit.maxRequests,
|
|
338
|
-
window: rateLimit.window,
|
|
339
|
-
keyBy: rateLimit.keyBy || 'ip',
|
|
340
|
-
headerName: rateLimit.headerName,
|
|
341
|
-
errorMessage: rateLimit.errorMessage || 'Rate limit exceeded. Please try again later.'
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Create a basic authentication route pattern
|
|
349
|
-
* @param baseRoute Base route to add authentication to
|
|
350
|
-
* @param auth Authentication configuration
|
|
351
|
-
* @returns Route with basic authentication
|
|
352
|
-
*/
|
|
353
|
-
export function addBasicAuth(
|
|
354
|
-
baseRoute: IRouteConfig,
|
|
355
|
-
auth: {
|
|
356
|
-
users: Array<{ username: string; password: string }>;
|
|
357
|
-
realm?: string;
|
|
358
|
-
excludePaths?: string[];
|
|
359
|
-
}
|
|
360
|
-
): IRouteConfig {
|
|
361
|
-
return mergeRouteConfigs(baseRoute, {
|
|
362
|
-
security: {
|
|
363
|
-
basicAuth: {
|
|
364
|
-
enabled: true,
|
|
365
|
-
users: auth.users,
|
|
366
|
-
realm: auth.realm || 'Restricted Area',
|
|
367
|
-
excludePaths: auth.excludePaths || []
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Create a JWT authentication route pattern
|
|
375
|
-
* @param baseRoute Base route to add JWT authentication to
|
|
376
|
-
* @param jwt JWT authentication configuration
|
|
377
|
-
* @returns Route with JWT authentication
|
|
378
|
-
*/
|
|
379
|
-
export function addJwtAuth(
|
|
380
|
-
baseRoute: IRouteConfig,
|
|
381
|
-
jwt: {
|
|
382
|
-
secret: string;
|
|
383
|
-
algorithm?: string;
|
|
384
|
-
issuer?: string;
|
|
385
|
-
audience?: string;
|
|
386
|
-
expiresIn?: number; // Time in seconds
|
|
387
|
-
excludePaths?: string[];
|
|
388
|
-
}
|
|
389
|
-
): IRouteConfig {
|
|
390
|
-
return mergeRouteConfigs(baseRoute, {
|
|
391
|
-
security: {
|
|
392
|
-
jwtAuth: {
|
|
393
|
-
enabled: true,
|
|
394
|
-
secret: jwt.secret,
|
|
395
|
-
algorithm: jwt.algorithm || 'HS256',
|
|
396
|
-
issuer: jwt.issuer,
|
|
397
|
-
audience: jwt.audience,
|
|
398
|
-
expiresIn: jwt.expiresIn,
|
|
399
|
-
excludePaths: jwt.excludePaths || []
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|