@push.rocks/smartproxy 26.3.0 → 27.0.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.
Files changed (57) hide show
  1. package/changelog.md +7 -0
  2. package/dist_rust/rustproxy_linux_amd64 +0 -0
  3. package/dist_rust/rustproxy_linux_arm64 +0 -0
  4. package/dist_ts/00_commitinfo_data.js +1 -1
  5. package/dist_ts/core/models/wrapped-socket.js +4 -1
  6. package/dist_ts/core/routing/route-manager.js +9 -7
  7. package/dist_ts/proxies/smart-proxy/datagram-handler-server.js +7 -5
  8. package/dist_ts/proxies/smart-proxy/route-preprocessor.js +6 -8
  9. package/dist_ts/proxies/smart-proxy/rust-metrics-adapter.js +186 -184
  10. package/dist_ts/proxies/smart-proxy/rust-proxy-bridge.js +2 -1
  11. package/dist_ts/proxies/smart-proxy/smart-proxy.js +12 -6
  12. package/dist_ts/proxies/smart-proxy/socket-handler-server.js +5 -3
  13. package/dist_ts/proxies/smart-proxy/utils/concurrency-semaphore.js +4 -3
  14. package/dist_ts/proxies/smart-proxy/utils/index.d.ts +2 -3
  15. package/dist_ts/proxies/smart-proxy/utils/index.js +4 -6
  16. package/dist_ts/proxies/smart-proxy/utils/mutex.js +3 -5
  17. package/dist_ts/proxies/smart-proxy/utils/route-validator.js +7 -7
  18. package/dist_ts/proxies/smart-proxy/utils/{route-helpers/socket-handlers.d.ts → socket-handlers.d.ts} +2 -10
  19. package/dist_ts/proxies/smart-proxy/utils/socket-handlers.js +268 -0
  20. package/dist_ts/routing/models/http-types.js +5 -1
  21. package/package.json +1 -1
  22. package/readme.hints.md +42 -20
  23. package/readme.md +144 -146
  24. package/ts/00_commitinfo_data.ts +1 -1
  25. package/ts/proxies/smart-proxy/utils/index.ts +3 -11
  26. package/ts/proxies/smart-proxy/utils/{route-helpers/socket-handlers.ts → socket-handlers.ts} +3 -31
  27. package/dist_ts/proxies/smart-proxy/utils/route-helpers/api-helpers.d.ts +0 -49
  28. package/dist_ts/proxies/smart-proxy/utils/route-helpers/api-helpers.js +0 -108
  29. package/dist_ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.d.ts +0 -57
  30. package/dist_ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.js +0 -90
  31. package/dist_ts/proxies/smart-proxy/utils/route-helpers/http-helpers.d.ts +0 -17
  32. package/dist_ts/proxies/smart-proxy/utils/route-helpers/http-helpers.js +0 -32
  33. package/dist_ts/proxies/smart-proxy/utils/route-helpers/https-helpers.d.ts +0 -68
  34. package/dist_ts/proxies/smart-proxy/utils/route-helpers/https-helpers.js +0 -117
  35. package/dist_ts/proxies/smart-proxy/utils/route-helpers/index.d.ts +0 -17
  36. package/dist_ts/proxies/smart-proxy/utils/route-helpers/index.js +0 -27
  37. package/dist_ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.d.ts +0 -63
  38. package/dist_ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.js +0 -105
  39. package/dist_ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.d.ts +0 -83
  40. package/dist_ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.js +0 -126
  41. package/dist_ts/proxies/smart-proxy/utils/route-helpers/security-helpers.d.ts +0 -47
  42. package/dist_ts/proxies/smart-proxy/utils/route-helpers/security-helpers.js +0 -66
  43. package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.js +0 -286
  44. package/dist_ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.d.ts +0 -46
  45. package/dist_ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.js +0 -67
  46. package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +0 -9
  47. package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +0 -11
  48. package/ts/proxies/smart-proxy/utils/route-helpers/api-helpers.ts +0 -144
  49. package/ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.ts +0 -125
  50. package/ts/proxies/smart-proxy/utils/route-helpers/http-helpers.ts +0 -40
  51. package/ts/proxies/smart-proxy/utils/route-helpers/https-helpers.ts +0 -163
  52. package/ts/proxies/smart-proxy/utils/route-helpers/index.ts +0 -62
  53. package/ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.ts +0 -154
  54. package/ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.ts +0 -202
  55. package/ts/proxies/smart-proxy/utils/route-helpers/security-helpers.ts +0 -96
  56. package/ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.ts +0 -98
  57. package/ts/proxies/smart-proxy/utils/route-helpers.ts +0 -11
@@ -1,46 +0,0 @@
1
- /**
2
- * WebSocket Route Helper Functions
3
- *
4
- * This module provides utility functions for creating WebSocket route configurations.
5
- */
6
- import type { IRouteConfig } from '../../models/route-types.js';
7
- /**
8
- * Create a WebSocket route configuration
9
- * @param domains Domain(s) to match
10
- * @param targetOrPath Target server OR WebSocket path (legacy)
11
- * @param targetOrOptions Target server (legacy) OR options
12
- * @param options Additional route options (legacy)
13
- * @returns Route configuration object
14
- */
15
- export declare function createWebSocketRoute(domains: string | string[], targetOrPath: {
16
- host: string | string[];
17
- port: number;
18
- } | string, targetOrOptions?: {
19
- host: string | string[];
20
- port: number;
21
- } | {
22
- useTls?: boolean;
23
- certificate?: 'auto' | {
24
- key: string;
25
- cert: string;
26
- };
27
- path?: string;
28
- httpPort?: number | number[];
29
- httpsPort?: number | number[];
30
- pingInterval?: number;
31
- pingTimeout?: number;
32
- name?: string;
33
- [key: string]: any;
34
- }, options?: {
35
- useTls?: boolean;
36
- certificate?: 'auto' | {
37
- key: string;
38
- cert: string;
39
- };
40
- httpPort?: number | number[];
41
- httpsPort?: number | number[];
42
- pingInterval?: number;
43
- pingTimeout?: number;
44
- name?: string;
45
- [key: string]: any;
46
- }): IRouteConfig;
@@ -1,67 +0,0 @@
1
- /**
2
- * WebSocket Route Helper Functions
3
- *
4
- * This module provides utility functions for creating WebSocket route configurations.
5
- */
6
- /**
7
- * Create a WebSocket route configuration
8
- * @param domains Domain(s) to match
9
- * @param targetOrPath Target server OR WebSocket path (legacy)
10
- * @param targetOrOptions Target server (legacy) OR options
11
- * @param options Additional route options (legacy)
12
- * @returns Route configuration object
13
- */
14
- export function createWebSocketRoute(domains, targetOrPath, targetOrOptions, options) {
15
- // Handle different signatures
16
- let target;
17
- let wsPath;
18
- let finalOptions;
19
- if (typeof targetOrPath === 'string') {
20
- // Legacy signature: (domains, path, target, options)
21
- wsPath = targetOrPath;
22
- target = targetOrOptions;
23
- finalOptions = options || {};
24
- }
25
- else {
26
- // New signature: (domains, target, options)
27
- target = targetOrPath;
28
- finalOptions = targetOrOptions || {};
29
- wsPath = finalOptions.path || '/ws';
30
- }
31
- // Normalize WebSocket path
32
- const normalizedPath = wsPath.startsWith('/') ? wsPath : `/${wsPath}`;
33
- // Create route match
34
- const match = {
35
- ports: finalOptions.useTls
36
- ? (finalOptions.httpsPort || 443)
37
- : (finalOptions.httpPort || 80),
38
- domains,
39
- path: normalizedPath
40
- };
41
- // Create route action
42
- const action = {
43
- type: 'forward',
44
- targets: [target],
45
- websocket: {
46
- enabled: true,
47
- pingInterval: finalOptions.pingInterval || 30000, // 30 seconds
48
- pingTimeout: finalOptions.pingTimeout || 5000 // 5 seconds
49
- }
50
- };
51
- // Add TLS configuration if using HTTPS
52
- if (finalOptions.useTls) {
53
- action.tls = {
54
- mode: 'terminate',
55
- certificate: finalOptions.certificate || 'auto'
56
- };
57
- }
58
- // Create the route config
59
- return {
60
- match,
61
- action,
62
- name: finalOptions.name || `WebSocket Route ${normalizedPath} for ${Array.isArray(domains) ? domains.join(', ') : domains}`,
63
- priority: finalOptions.priority || 100, // Higher priority for WebSocket routes
64
- ...finalOptions
65
- };
66
- }
67
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2Vic29ja2V0LWhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi90cy9wcm94a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
1
- /**
2
- * Route Helper Functions
3
- *
4
- * This file re-exports all route helper functions for backwards compatibility.
5
- * The actual implementations have been split into focused modules in the route-helpers/ directory.
6
- *
7
- * @see ./route-helpers/index.ts for the modular exports
8
- */
9
- export * from './route-helpers/index.js';
@@ -1,11 +0,0 @@
1
- /**
2
- * Route Helper Functions
3
- *
4
- * This file re-exports all route helper functions for backwards compatibility.
5
- * The actual implementations have been split into focused modules in the route-helpers/ directory.
6
- *
7
- * @see ./route-helpers/index.ts for the modular exports
8
- */
9
- // Re-export everything from the modular helpers
10
- export * from './route-helpers/index.js';
11
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUtaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3RzL3Byb3hpZXMvc21hcnQtcHJveHkvdXRpbHMvcm91dGUtaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7OztHQU9HO0FBRUgsZ0RBQWdEO0FBQ2hELGNBQWMsMEJBQTBCLENBQUMifQ==
@@ -1,144 +0,0 @@
1
- /**
2
- * API Route Helper Functions
3
- *
4
- * This module provides utility functions for creating API route configurations.
5
- */
6
-
7
- import type { IRouteConfig, IRouteMatch, IRouteAction } from '../../models/route-types.js';
8
- import { mergeRouteConfigs } from '../route-utils.js';
9
- import { createHttpRoute } from './http-helpers.js';
10
- import { createHttpsTerminateRoute } from './https-helpers.js';
11
-
12
- /**
13
- * Create an API route configuration
14
- * @param domains Domain(s) to match
15
- * @param apiPath API base path (e.g., "/api")
16
- * @param target Target host and port
17
- * @param options Additional route options
18
- * @returns Route configuration object
19
- */
20
- export function createApiRoute(
21
- domains: string | string[],
22
- apiPath: string,
23
- target: { host: string | string[]; port: number },
24
- options: {
25
- useTls?: boolean;
26
- certificate?: 'auto' | { key: string; cert: string };
27
- addCorsHeaders?: boolean;
28
- httpPort?: number | number[];
29
- httpsPort?: number | number[];
30
- name?: string;
31
- [key: string]: any;
32
- } = {}
33
- ): IRouteConfig {
34
- // Normalize API path
35
- const normalizedPath = apiPath.startsWith('/') ? apiPath : `/${apiPath}`;
36
- const pathWithWildcard = normalizedPath.endsWith('/')
37
- ? `${normalizedPath}*`
38
- : `${normalizedPath}/*`;
39
-
40
- // Create route match
41
- const match: IRouteMatch = {
42
- ports: options.useTls
43
- ? (options.httpsPort || 443)
44
- : (options.httpPort || 80),
45
- domains,
46
- path: pathWithWildcard
47
- };
48
-
49
- // Create route action
50
- const action: IRouteAction = {
51
- type: 'forward',
52
- targets: [target]
53
- };
54
-
55
- // Add TLS configuration if using HTTPS
56
- if (options.useTls) {
57
- action.tls = {
58
- mode: 'terminate',
59
- certificate: options.certificate || 'auto'
60
- };
61
- }
62
-
63
- // Add CORS headers if requested
64
- const headers: Record<string, Record<string, string>> = {};
65
- if (options.addCorsHeaders) {
66
- headers.response = {
67
- 'Access-Control-Allow-Origin': '*',
68
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
69
- 'Access-Control-Allow-Headers': 'Content-Type, Authorization',
70
- 'Access-Control-Max-Age': '86400'
71
- };
72
- }
73
-
74
- // Create the route config
75
- return {
76
- match,
77
- action,
78
- headers: Object.keys(headers).length > 0 ? headers : undefined,
79
- name: options.name || `API Route ${normalizedPath} for ${Array.isArray(domains) ? domains.join(', ') : domains}`,
80
- priority: options.priority || 100, // Higher priority for specific path matches
81
- ...options
82
- };
83
- }
84
-
85
- /**
86
- * Create an API Gateway route pattern
87
- * @param domains Domain(s) to match
88
- * @param apiBasePath Base path for API endpoints (e.g., '/api')
89
- * @param target Target host and port
90
- * @param options Additional route options
91
- * @returns API route configuration
92
- */
93
- export function createApiGatewayRoute(
94
- domains: string | string[],
95
- apiBasePath: string,
96
- target: { host: string | string[]; port: number },
97
- options: {
98
- useTls?: boolean;
99
- certificate?: 'auto' | { key: string; cert: string };
100
- addCorsHeaders?: boolean;
101
- [key: string]: any;
102
- } = {}
103
- ): IRouteConfig {
104
- // Normalize apiBasePath to ensure it starts with / and doesn't end with /
105
- const normalizedPath = apiBasePath.startsWith('/')
106
- ? apiBasePath
107
- : `/${apiBasePath}`;
108
-
109
- // Add wildcard to path to match all API endpoints
110
- const apiPath = normalizedPath.endsWith('/')
111
- ? `${normalizedPath}*`
112
- : `${normalizedPath}/*`;
113
-
114
- // Create base route
115
- const baseRoute = options.useTls
116
- ? createHttpsTerminateRoute(domains, target, {
117
- certificate: options.certificate || 'auto'
118
- })
119
- : createHttpRoute(domains, target);
120
-
121
- // Add API-specific configurations
122
- const apiRoute: Partial<IRouteConfig> = {
123
- match: {
124
- ...baseRoute.match,
125
- path: apiPath
126
- },
127
- name: options.name || `API Gateway: ${apiPath} -> ${Array.isArray(target.host) ? target.host.join(', ') : target.host}:${target.port}`,
128
- priority: options.priority || 100 // Higher priority for specific path matching
129
- };
130
-
131
- // Add CORS headers if requested
132
- if (options.addCorsHeaders) {
133
- apiRoute.headers = {
134
- response: {
135
- 'Access-Control-Allow-Origin': '*',
136
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
137
- 'Access-Control-Allow-Headers': 'Content-Type, Authorization',
138
- 'Access-Control-Max-Age': '86400'
139
- }
140
- };
141
- }
142
-
143
- return mergeRouteConfigs(baseRoute, apiRoute);
144
- }
@@ -1,125 +0,0 @@
1
- /**
2
- * Dynamic Route Helper Functions
3
- *
4
- * This module provides utility functions for creating dynamic routes
5
- * with context-based host and port mapping.
6
- */
7
-
8
- import type { IRouteConfig, IRouteMatch, IRouteAction, TPortRange, IRouteContext } from '../../models/route-types.js';
9
-
10
- /**
11
- * Create a helper function that applies a port offset
12
- * @param offset The offset to apply to the matched port
13
- * @returns A function that adds the offset to the matched port
14
- */
15
- export function createPortOffset(offset: number): (context: IRouteContext) => number {
16
- return (context: IRouteContext) => context.port + offset;
17
- }
18
-
19
- /**
20
- * Create a port mapping route with context-based port function
21
- * @param options Port mapping route options
22
- * @returns Route configuration object
23
- */
24
- export function createPortMappingRoute(options: {
25
- sourcePortRange: TPortRange;
26
- targetHost: string | string[] | ((context: IRouteContext) => string | string[]);
27
- portMapper: (context: IRouteContext) => number;
28
- name?: string;
29
- domains?: string | string[];
30
- priority?: number;
31
- [key: string]: any;
32
- }): IRouteConfig {
33
- // Create route match
34
- const match: IRouteMatch = {
35
- ports: options.sourcePortRange,
36
- domains: options.domains
37
- };
38
-
39
- // Create route action
40
- const action: IRouteAction = {
41
- type: 'forward',
42
- targets: [{
43
- host: options.targetHost,
44
- port: options.portMapper
45
- }]
46
- };
47
-
48
- // Create the route config
49
- return {
50
- match,
51
- action,
52
- name: options.name || `Port Mapping Route for ${options.domains || 'all domains'}`,
53
- priority: options.priority,
54
- ...options
55
- };
56
- }
57
-
58
- /**
59
- * Create a simple offset port mapping route
60
- * @param options Offset port mapping route options
61
- * @returns Route configuration object
62
- */
63
- export function createOffsetPortMappingRoute(options: {
64
- ports: TPortRange;
65
- targetHost: string | string[];
66
- offset: number;
67
- name?: string;
68
- domains?: string | string[];
69
- priority?: number;
70
- [key: string]: any;
71
- }): IRouteConfig {
72
- const { ports, targetHost, offset, name, domains, priority, ...rest } = options;
73
- return createPortMappingRoute({
74
- sourcePortRange: ports,
75
- targetHost,
76
- portMapper: (context) => context.port + offset,
77
- name: name || `Offset Mapping (${offset > 0 ? '+' : ''}${offset}) for ${domains || 'all domains'}`,
78
- domains,
79
- priority,
80
- ...rest
81
- });
82
- }
83
-
84
- /**
85
- * Create a dynamic route with context-based host and port mapping
86
- * @param options Dynamic route options
87
- * @returns Route configuration object
88
- */
89
- export function createDynamicRoute(options: {
90
- ports: TPortRange;
91
- targetHost: (context: IRouteContext) => string | string[];
92
- portMapper: (context: IRouteContext) => number;
93
- name?: string;
94
- domains?: string | string[];
95
- path?: string;
96
- clientIp?: string[];
97
- priority?: number;
98
- [key: string]: any;
99
- }): IRouteConfig {
100
- // Create route match
101
- const match: IRouteMatch = {
102
- ports: options.ports,
103
- domains: options.domains,
104
- path: options.path,
105
- clientIp: options.clientIp
106
- };
107
-
108
- // Create route action
109
- const action: IRouteAction = {
110
- type: 'forward',
111
- targets: [{
112
- host: options.targetHost,
113
- port: options.portMapper
114
- }]
115
- };
116
-
117
- // Create the route config
118
- return {
119
- match,
120
- action,
121
- name: options.name || `Dynamic Route for ${options.domains || 'all domains'}`,
122
- priority: options.priority,
123
- ...options
124
- };
125
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * HTTP Route Helper Functions
3
- *
4
- * This module provides utility functions for creating HTTP route configurations.
5
- */
6
-
7
- import type { IRouteConfig, IRouteMatch, IRouteAction } from '../../models/route-types.js';
8
-
9
- /**
10
- * Create an HTTP-only route configuration
11
- * @param domains Domain(s) to match
12
- * @param target Target host and port
13
- * @param options Additional route options
14
- * @returns Route configuration object
15
- */
16
- export function createHttpRoute(
17
- domains: string | string[],
18
- target: { host: string | string[]; port: number },
19
- options: Partial<IRouteConfig> = {}
20
- ): IRouteConfig {
21
- // Create route match
22
- const match: IRouteMatch = {
23
- ports: options.match?.ports || 80,
24
- domains
25
- };
26
-
27
- // Create route action
28
- const action: IRouteAction = {
29
- type: 'forward',
30
- targets: [target]
31
- };
32
-
33
- // Create the route config
34
- return {
35
- match,
36
- action,
37
- name: options.name || `HTTP Route for ${Array.isArray(domains) ? domains.join(', ') : domains}`,
38
- ...options
39
- };
40
- }
@@ -1,163 +0,0 @@
1
- /**
2
- * HTTPS Route Helper Functions
3
- *
4
- * This module provides utility functions for creating HTTPS route configurations
5
- * including TLS termination and passthrough routes.
6
- */
7
-
8
- import type { IRouteConfig, IRouteMatch, IRouteAction } from '../../models/route-types.js';
9
- import { SocketHandlers } from './socket-handlers.js';
10
-
11
- /**
12
- * Create an HTTPS route with TLS termination
13
- * @param domains Domain(s) to match
14
- * @param target Target host and port
15
- * @param options Additional route options
16
- * @returns Route configuration object
17
- */
18
- export function createHttpsTerminateRoute(
19
- domains: string | string[],
20
- target: { host: string | string[]; port: number },
21
- options: {
22
- certificate?: 'auto' | { key: string; cert: string };
23
- httpPort?: number | number[];
24
- httpsPort?: number | number[];
25
- reencrypt?: boolean;
26
- name?: string;
27
- [key: string]: any;
28
- } = {}
29
- ): IRouteConfig {
30
- // Create route match
31
- const match: IRouteMatch = {
32
- ports: options.httpsPort || 443,
33
- domains
34
- };
35
-
36
- // Create route action
37
- const action: IRouteAction = {
38
- type: 'forward',
39
- targets: [target],
40
- tls: {
41
- mode: options.reencrypt ? 'terminate-and-reencrypt' : 'terminate',
42
- certificate: options.certificate || 'auto'
43
- }
44
- };
45
-
46
- // Create the route config
47
- return {
48
- match,
49
- action,
50
- name: options.name || `HTTPS Route for ${Array.isArray(domains) ? domains.join(', ') : domains}`,
51
- ...options
52
- };
53
- }
54
-
55
- /**
56
- * Create an HTTP to HTTPS redirect route
57
- * @param domains Domain(s) to match
58
- * @param httpsPort HTTPS port to redirect to (default: 443)
59
- * @param options Additional route options
60
- * @returns Route configuration object
61
- */
62
- export function createHttpToHttpsRedirect(
63
- domains: string | string[],
64
- httpsPort: number = 443,
65
- options: Partial<IRouteConfig> = {}
66
- ): IRouteConfig {
67
- // Create route match
68
- const match: IRouteMatch = {
69
- ports: options.match?.ports || 80,
70
- domains
71
- };
72
-
73
- // Create route action
74
- const action: IRouteAction = {
75
- type: 'socket-handler',
76
- socketHandler: SocketHandlers.httpRedirect(`https://{domain}:${httpsPort}{path}`, 301)
77
- };
78
-
79
- // Create the route config
80
- return {
81
- match,
82
- action,
83
- name: options.name || `HTTP to HTTPS Redirect for ${Array.isArray(domains) ? domains.join(', ') : domains}`,
84
- ...options
85
- };
86
- }
87
-
88
- /**
89
- * Create an HTTPS passthrough route (SNI-based forwarding without TLS termination)
90
- * @param domains Domain(s) to match
91
- * @param target Target host and port
92
- * @param options Additional route options
93
- * @returns Route configuration object
94
- */
95
- export function createHttpsPassthroughRoute(
96
- domains: string | string[],
97
- target: { host: string | string[]; port: number },
98
- options: Partial<IRouteConfig> = {}
99
- ): IRouteConfig {
100
- // Create route match
101
- const match: IRouteMatch = {
102
- ports: options.match?.ports || 443,
103
- domains
104
- };
105
-
106
- // Create route action
107
- const action: IRouteAction = {
108
- type: 'forward',
109
- targets: [target],
110
- tls: {
111
- mode: 'passthrough'
112
- }
113
- };
114
-
115
- // Create the route config
116
- return {
117
- match,
118
- action,
119
- name: options.name || `HTTPS Passthrough for ${Array.isArray(domains) ? domains.join(', ') : domains}`,
120
- ...options
121
- };
122
- }
123
-
124
- /**
125
- * Create a complete HTTPS server with HTTP to HTTPS redirects
126
- * @param domains Domain(s) to match
127
- * @param target Target host and port
128
- * @param options Additional configuration options
129
- * @returns Array of two route configurations (HTTPS and HTTP redirect)
130
- */
131
- export function createCompleteHttpsServer(
132
- domains: string | string[],
133
- target: { host: string | string[]; port: number },
134
- options: {
135
- certificate?: 'auto' | { key: string; cert: string };
136
- httpPort?: number | number[];
137
- httpsPort?: number | number[];
138
- reencrypt?: boolean;
139
- name?: string;
140
- [key: string]: any;
141
- } = {}
142
- ): IRouteConfig[] {
143
- // Create the HTTPS route
144
- const httpsRoute = createHttpsTerminateRoute(domains, target, options);
145
-
146
- // Create the HTTP redirect route
147
- const httpRedirectRoute = createHttpToHttpsRedirect(
148
- domains,
149
- // Extract the HTTPS port from the HTTPS route - ensure it's a number
150
- typeof options.httpsPort === 'number' ? options.httpsPort :
151
- Array.isArray(options.httpsPort) ? options.httpsPort[0] : 443,
152
- {
153
- // Set the HTTP port
154
- match: {
155
- ports: options.httpPort || 80,
156
- domains
157
- },
158
- name: `HTTP to HTTPS Redirect for ${Array.isArray(domains) ? domains.join(', ') : domains}`
159
- }
160
- );
161
-
162
- return [httpsRoute, httpRedirectRoute];
163
- }
@@ -1,62 +0,0 @@
1
- /**
2
- * Route Helper Functions
3
- *
4
- * This module provides utility functions for creating route configurations for common scenarios.
5
- * These functions aim to simplify the creation of route configurations for typical use cases.
6
- *
7
- * This barrel file re-exports all helper functions for backwards compatibility.
8
- */
9
-
10
- // HTTP helpers
11
- export { createHttpRoute } from './http-helpers.js';
12
-
13
- // HTTPS helpers
14
- export {
15
- createHttpsTerminateRoute,
16
- createHttpToHttpsRedirect,
17
- createHttpsPassthroughRoute,
18
- createCompleteHttpsServer
19
- } from './https-helpers.js';
20
-
21
- // WebSocket helpers
22
- export { createWebSocketRoute } from './websocket-helpers.js';
23
-
24
- // Load balancer helpers
25
- export {
26
- createLoadBalancerRoute,
27
- createSmartLoadBalancer
28
- } from './load-balancer-helpers.js';
29
-
30
- // NFTables helpers
31
- export {
32
- createNfTablesRoute,
33
- createNfTablesTerminateRoute,
34
- createCompleteNfTablesHttpsServer
35
- } from './nftables-helpers.js';
36
-
37
- // Dynamic routing helpers
38
- export {
39
- createPortOffset,
40
- createPortMappingRoute,
41
- createOffsetPortMappingRoute,
42
- createDynamicRoute
43
- } from './dynamic-helpers.js';
44
-
45
- // API helpers
46
- export {
47
- createApiRoute,
48
- createApiGatewayRoute
49
- } from './api-helpers.js';
50
-
51
- // Security helpers
52
- export {
53
- addRateLimiting,
54
- addBasicAuth,
55
- addJwtAuth
56
- } from './security-helpers.js';
57
-
58
- // Socket handlers
59
- export {
60
- SocketHandlers,
61
- createSocketHandlerRoute
62
- } from './socket-handlers.js';