@robiki/proxy 1.0.2 → 1.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/README.de.md +101 -395
- package/README.es.md +99 -394
- package/README.ja.md +100 -395
- package/README.md +100 -394
- package/README.pl.md +100 -395
- package/README.ru.md +99 -394
- package/README.zh.md +99 -394
- package/dist/{config-CeJ1tf8T.d.ts → config-CCOdQL7F.d.ts} +5 -11
- package/dist/index.d.ts +3 -2
- package/dist/index.js +51 -72
- package/dist/utils/config.d.ts +1 -1
- package/dist/utils/config.js +37 -20
- package/package.json +2 -5
- package/dist/config-CQ7zIaQt.d.ts +0 -172
- package/dist/config-_6LOsppp.d.ts +0 -180
|
@@ -154,21 +154,15 @@ declare class ProxyConfig {
|
|
|
154
154
|
getConfig(): ServerConfig;
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
|
-
* Load configuration with cascading priority:
|
|
157
|
+
* Load configuration with cascading priority (async):
|
|
158
158
|
* 1. Programmatic config (highest priority)
|
|
159
159
|
* 2. Environment variables
|
|
160
160
|
* 3. Config file
|
|
161
161
|
* 4. Defaults (lowest priority)
|
|
162
|
+
*
|
|
163
|
+
* Supports all config file types: .json, .cjs, .ts, .js, .mjs
|
|
162
164
|
*/
|
|
163
|
-
declare function loadConfig(programmaticConfig?: Partial<ServerConfig>): ProxyConfig
|
|
164
|
-
/**
|
|
165
|
-
* Load configuration from a file (deprecated - use loadConfig instead)
|
|
166
|
-
*/
|
|
167
|
-
declare function loadConfigFromFile(path: string): ProxyConfig;
|
|
168
|
-
/**
|
|
169
|
-
* Load configuration from environment variables (deprecated - use loadConfig instead)
|
|
170
|
-
*/
|
|
171
|
-
declare function loadConfigFromEnv(): ProxyConfig;
|
|
165
|
+
declare function loadConfig(programmaticConfig?: Partial<ServerConfig>): Promise<ProxyConfig>;
|
|
172
166
|
|
|
173
|
-
export { ProxyConfig as P, RequestType as e,
|
|
167
|
+
export { ProxyConfig as P, RequestType as e, loadConfig as l };
|
|
174
168
|
export type { CorsConfig as C, ForwardValidationResult as F, Router as R, ServerConfig as S, TLSWebSocket as T, WebSocketRouter as W, Streamer as a, RouteConfig as b, CertificateConfig as c, ConnectionInfo as d };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as ProxyConfig, T as TLSWebSocket, S as ServerConfig, R as Router, a as Streamer, W as WebSocketRouter } from './config-
|
|
2
|
-
export { c as CertificateConfig, d as ConnectionInfo, C as CorsConfig, F as ForwardValidationResult, e as RequestType, b as RouteConfig, l as loadConfig } from './config-
|
|
1
|
+
import { P as ProxyConfig, T as TLSWebSocket, S as ServerConfig, R as Router, a as Streamer, W as WebSocketRouter } from './config-CCOdQL7F.js';
|
|
2
|
+
export { c as CertificateConfig, d as ConnectionInfo, C as CorsConfig, F as ForwardValidationResult, e as RequestType, b as RouteConfig, l as loadConfig } from './config-CCOdQL7F.js';
|
|
3
3
|
import { IncomingMessage, ServerResponse, IncomingHttpHeaders as IncomingHttpHeaders$1 } from 'node:http';
|
|
4
4
|
import { ServerHttp2Stream, IncomingHttpHeaders } from 'node:http2';
|
|
5
5
|
import 'node:tls';
|
|
@@ -33,6 +33,7 @@ declare class ProxyServer {
|
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Create and start a proxy server
|
|
36
|
+
* Supports all config file types: .json, .cjs, .ts, .js, .mjs
|
|
36
37
|
*/
|
|
37
38
|
declare function createProxy(config?: Partial<ServerConfig>): Promise<ProxyServer>;
|
|
38
39
|
/**
|
package/dist/index.js
CHANGED
|
@@ -485,80 +485,59 @@ class ProxyServer {
|
|
|
485
485
|
return this.config;
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
|
-
function createProxy(config) {
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
return proxy.start().then(() => proxy);
|
|
494
|
-
};
|
|
495
|
-
return Promise.resolve().then(() => createProxyInstance()).then((proxy) => startProxy(proxy));
|
|
488
|
+
async function createProxy(config) {
|
|
489
|
+
const proxyConfig = await loadConfig(config);
|
|
490
|
+
const proxy = new ProxyServer(proxyConfig);
|
|
491
|
+
await proxy.start();
|
|
492
|
+
return proxy;
|
|
496
493
|
}
|
|
497
|
-
function createCustomProxy(config, handlers) {
|
|
494
|
+
async function createCustomProxy(config, handlers) {
|
|
498
495
|
const servers = [];
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
console.log("STARTING CUSTOM PROXY SERVER....");
|
|
509
|
-
return cfg;
|
|
510
|
-
};
|
|
511
|
-
const createServers = ({ ssl, ports, proxyConfig }) => {
|
|
512
|
-
const boundRestHandler = (req, res) => {
|
|
513
|
-
if (req.url === "/robiki-proxy/health" && req.method === "GET") {
|
|
514
|
-
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
515
|
-
res.end("OK");
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
return restAPIProxyHandler(req, res, proxyConfig);
|
|
519
|
-
};
|
|
520
|
-
const boundStreamHandler = (stream, headers) => streamAPIProxyHandler(stream, headers, proxyConfig);
|
|
521
|
-
const boundWebsocketHandler = (req, socket, headers) => websocketAPIProxyHandler(req, socket, headers, proxyConfig);
|
|
522
|
-
for (const port of ports) {
|
|
523
|
-
let server;
|
|
524
|
-
if (ssl) {
|
|
525
|
-
server = http2(handlers.rest || boundRestHandler, handlers.stream || boundStreamHandler, {
|
|
526
|
-
...ssl,
|
|
527
|
-
port
|
|
528
|
-
});
|
|
529
|
-
} else {
|
|
530
|
-
server = http(handlers.rest || boundRestHandler, { port });
|
|
531
|
-
}
|
|
532
|
-
websocket(server, handlers.websocket || boundWebsocketHandler, (info) => proxyConfig.validate(info));
|
|
533
|
-
servers.push(server);
|
|
496
|
+
console.log("STARTING CUSTOM PROXY SERVER....");
|
|
497
|
+
const proxyConfig = await loadConfig(config);
|
|
498
|
+
const ssl = proxyConfig.getSSL();
|
|
499
|
+
const ports = proxyConfig.getPorts();
|
|
500
|
+
const boundRestHandler = (req, res) => {
|
|
501
|
+
if (req.url === "/robiki-proxy/health" && req.method === "GET") {
|
|
502
|
+
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
503
|
+
res.end("OK");
|
|
504
|
+
return;
|
|
534
505
|
}
|
|
535
|
-
return proxyConfig;
|
|
536
|
-
};
|
|
537
|
-
const createProxyInstance = (proxyConfig) => {
|
|
538
|
-
console.log("Custom proxy server started successfully");
|
|
539
|
-
return {
|
|
540
|
-
getConfig: () => proxyConfig,
|
|
541
|
-
start: async () => {
|
|
542
|
-
},
|
|
543
|
-
stop: async () => {
|
|
544
|
-
await Promise.all(
|
|
545
|
-
servers.map(
|
|
546
|
-
(server) => new Promise((resolve, reject) => {
|
|
547
|
-
server.close((err) => {
|
|
548
|
-
if (err) reject(err);
|
|
549
|
-
else resolve();
|
|
550
|
-
});
|
|
551
|
-
})
|
|
552
|
-
)
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
};
|
|
506
|
+
return restAPIProxyHandler(req, res, proxyConfig);
|
|
556
507
|
};
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
508
|
+
const boundStreamHandler = (stream, headers) => streamAPIProxyHandler(stream, headers, proxyConfig);
|
|
509
|
+
const boundWebsocketHandler = (req, socket, headers) => websocketAPIProxyHandler(req, socket, headers, proxyConfig);
|
|
510
|
+
for (const port of ports) {
|
|
511
|
+
let server;
|
|
512
|
+
if (ssl) {
|
|
513
|
+
server = http2(handlers.rest || boundRestHandler, handlers.stream || boundStreamHandler, {
|
|
514
|
+
...ssl,
|
|
515
|
+
port
|
|
516
|
+
});
|
|
517
|
+
} else {
|
|
518
|
+
server = http(handlers.rest || boundRestHandler, { port });
|
|
519
|
+
}
|
|
520
|
+
websocket(server, handlers.websocket || boundWebsocketHandler, (info) => proxyConfig.validate(info));
|
|
521
|
+
servers.push(server);
|
|
522
|
+
}
|
|
523
|
+
console.log("Custom proxy server started successfully");
|
|
524
|
+
return {
|
|
525
|
+
getConfig: () => proxyConfig,
|
|
526
|
+
start: async () => {
|
|
527
|
+
},
|
|
528
|
+
stop: async () => {
|
|
529
|
+
await Promise.all(
|
|
530
|
+
servers.map(
|
|
531
|
+
(server) => new Promise((resolve, reject) => {
|
|
532
|
+
server.close((err) => {
|
|
533
|
+
if (err) reject(err);
|
|
534
|
+
else resolve();
|
|
535
|
+
});
|
|
536
|
+
})
|
|
537
|
+
)
|
|
538
|
+
);
|
|
539
|
+
}
|
|
560
540
|
};
|
|
561
|
-
return Promise.resolve().then(() => initializeConfig()).then((cfg) => logStartup(cfg)).then((cfg) => createServers(cfg)).then((proxyConfig) => createProxyInstance(proxyConfig)).catch((error) => handleError(error));
|
|
562
541
|
}
|
|
563
542
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
564
543
|
const setupErrorHandlers = () => {
|
|
@@ -569,15 +548,15 @@ if (import.meta.url === `file://${process.argv[1]}`) {
|
|
|
569
548
|
console.log("UNHANDLED REJECTION: ", reason, promise);
|
|
570
549
|
});
|
|
571
550
|
};
|
|
572
|
-
const startProxyServer = () => {
|
|
573
|
-
return createProxy();
|
|
551
|
+
const startProxyServer = async () => {
|
|
552
|
+
return await createProxy();
|
|
574
553
|
};
|
|
575
554
|
const handleStartupError = (error) => {
|
|
576
555
|
console.error("Failed to start proxy server:", error);
|
|
577
556
|
process.exit(1);
|
|
578
557
|
};
|
|
579
558
|
setupErrorHandlers();
|
|
580
|
-
|
|
559
|
+
startProxyServer().catch((error) => handleStartupError(error));
|
|
581
560
|
}
|
|
582
561
|
|
|
583
562
|
export { ProxyServer, RequestType, createCustomProxy, createProxy, loadConfig, restAPIProxyHandler, streamAPIProxyHandler, websocketAPIProxyHandler };
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'node:http';
|
|
2
|
-
export { c as CertificateConfig, C as CorsConfig, P as ProxyConfig, b as RouteConfig, S as ServerConfig, l as loadConfig
|
|
2
|
+
export { c as CertificateConfig, C as CorsConfig, P as ProxyConfig, b as RouteConfig, S as ServerConfig, l as loadConfig } from '../config-CCOdQL7F.js';
|
|
3
3
|
import 'node:http2';
|
|
4
4
|
import 'node:tls';
|
|
5
5
|
import 'ws';
|
package/dist/utils/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
1
|
+
import{createRequire as _pkgrollCR}from"node:module";const require=_pkgrollCR(import.meta.url);import { readFileSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
|
|
4
4
|
class ProxyConfig {
|
|
@@ -175,16 +175,47 @@ function getConfigFromEnv() {
|
|
|
175
175
|
}
|
|
176
176
|
return config;
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function loadTypeScriptConfig(resolvedPath) {
|
|
179
|
+
try {
|
|
180
|
+
const { register } = require("tsx/cjs/api");
|
|
181
|
+
const unregister = register();
|
|
182
|
+
try {
|
|
183
|
+
delete require.cache[resolvedPath];
|
|
184
|
+
const configModule = require(resolvedPath);
|
|
185
|
+
return configModule.default || configModule;
|
|
186
|
+
} finally {
|
|
187
|
+
unregister();
|
|
188
|
+
}
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.warn("Failed to load TypeScript config file:", error);
|
|
191
|
+
console.warn("Make sure tsx is installed: npm install tsx or yarn add tsx");
|
|
192
|
+
return {};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function getConfigFromFile() {
|
|
179
196
|
const configPath = process.env.PROXY_CONFIG || "./proxy.config.json";
|
|
180
197
|
try {
|
|
181
|
-
const
|
|
198
|
+
const resolvedPath = resolve(configPath);
|
|
199
|
+
if (resolvedPath.endsWith(".ts")) {
|
|
200
|
+
return loadTypeScriptConfig(resolvedPath);
|
|
201
|
+
}
|
|
202
|
+
if (resolvedPath.endsWith(".js") || resolvedPath.endsWith(".mjs")) {
|
|
203
|
+
const fileUrl = `file://${resolvedPath}`;
|
|
204
|
+
const configModule = await import(fileUrl);
|
|
205
|
+
return configModule.default || configModule;
|
|
206
|
+
}
|
|
207
|
+
if (resolvedPath.endsWith(".cjs")) {
|
|
208
|
+
delete require.cache[resolvedPath];
|
|
209
|
+
const configModule = require(resolvedPath);
|
|
210
|
+
return configModule.default || configModule;
|
|
211
|
+
}
|
|
212
|
+
const configFile = readFileSync(resolvedPath, "utf-8");
|
|
182
213
|
return JSON.parse(configFile);
|
|
183
214
|
} catch (error) {
|
|
184
215
|
return {};
|
|
185
216
|
}
|
|
186
217
|
}
|
|
187
|
-
function loadConfig(programmaticConfig) {
|
|
218
|
+
async function loadConfig(programmaticConfig) {
|
|
188
219
|
const defaults = {
|
|
189
220
|
routes: {},
|
|
190
221
|
cors: {
|
|
@@ -192,24 +223,10 @@ function loadConfig(programmaticConfig) {
|
|
|
192
223
|
credentials: true
|
|
193
224
|
}
|
|
194
225
|
};
|
|
195
|
-
const fileConfig = getConfigFromFile();
|
|
226
|
+
const fileConfig = await getConfigFromFile();
|
|
196
227
|
const envConfig = getConfigFromEnv();
|
|
197
228
|
const merged = deepMerge(defaults, fileConfig, envConfig, programmaticConfig || {});
|
|
198
229
|
return new ProxyConfig(merged);
|
|
199
230
|
}
|
|
200
|
-
function loadConfigFromFile(path) {
|
|
201
|
-
try {
|
|
202
|
-
const configFile = readFileSync(resolve(path), "utf-8");
|
|
203
|
-
const config = JSON.parse(configFile);
|
|
204
|
-
return new ProxyConfig(config);
|
|
205
|
-
} catch (error) {
|
|
206
|
-
console.error("Failed to load configuration file:", error);
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function loadConfigFromEnv() {
|
|
211
|
-
const config = getConfigFromEnv();
|
|
212
|
-
return new ProxyConfig(config);
|
|
213
|
-
}
|
|
214
231
|
|
|
215
|
-
export { ProxyConfig, loadConfig
|
|
232
|
+
export { ProxyConfig, loadConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robiki/proxy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A flexible HTTP/2 proxy server with WebSocket support, configurable routing, CORS, and validation. Use as npm package or Docker container.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"proxy",
|
|
@@ -32,10 +32,6 @@
|
|
|
32
32
|
"import": "./dist/index.js",
|
|
33
33
|
"types": "./dist/index.d.ts"
|
|
34
34
|
},
|
|
35
|
-
"./proxy": {
|
|
36
|
-
"import": "./dist/proxy.js",
|
|
37
|
-
"types": "./dist/proxy.d.ts"
|
|
38
|
-
},
|
|
39
35
|
"./config": {
|
|
40
36
|
"import": "./dist/utils/config.js",
|
|
41
37
|
"types": "./dist/utils/config.d.ts"
|
|
@@ -78,6 +74,7 @@
|
|
|
78
74
|
},
|
|
79
75
|
"dependencies": {
|
|
80
76
|
"@types/ws": "8.18.1",
|
|
77
|
+
"tsx": "4.19.2",
|
|
81
78
|
"ws": "8.19.0"
|
|
82
79
|
},
|
|
83
80
|
"engines": {
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { OutgoingHttpHeaders, IncomingMessage } from 'node:http';
|
|
2
|
-
import { IncomingHttpHeaders } from 'node:http2';
|
|
3
|
-
import { TLSSocket } from 'node:tls';
|
|
4
|
-
import WebSocket from 'ws';
|
|
5
|
-
|
|
6
|
-
declare enum RequestType {
|
|
7
|
-
API = "api",
|
|
8
|
-
STREAM = "stream",
|
|
9
|
-
WEBSOCKET = "websocket"
|
|
10
|
-
}
|
|
11
|
-
interface TLSWebSocket extends WebSocket {
|
|
12
|
-
_socket: TLSSocket;
|
|
13
|
-
}
|
|
14
|
-
type Router = (req: any, res: any) => void;
|
|
15
|
-
type WebSocketRouter = (req: IncomingMessage, socket: TLSWebSocket, headers: IncomingHttpHeaders) => void;
|
|
16
|
-
type Streamer = (stream: any, headers: any, flags: any) => void;
|
|
17
|
-
interface ForwardValidationResult {
|
|
18
|
-
status: boolean;
|
|
19
|
-
message?: string;
|
|
20
|
-
code?: number;
|
|
21
|
-
headers?: OutgoingHttpHeaders;
|
|
22
|
-
}
|
|
23
|
-
interface ConnectionInfo {
|
|
24
|
-
id: number;
|
|
25
|
-
method: string;
|
|
26
|
-
path: string;
|
|
27
|
-
remoteAddress: string;
|
|
28
|
-
scheme: string;
|
|
29
|
-
authority: string;
|
|
30
|
-
origin: string;
|
|
31
|
-
headers: IncomingHttpHeaders;
|
|
32
|
-
query: URLSearchParams;
|
|
33
|
-
type: RequestType;
|
|
34
|
-
respond: (status: number, headers?: Record<string, string>, body?: string) => void;
|
|
35
|
-
end: (body?: string) => void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Route configuration for a specific domain/host
|
|
40
|
-
*/
|
|
41
|
-
interface RouteConfig {
|
|
42
|
-
/** Target host:port to proxy to */
|
|
43
|
-
target: string;
|
|
44
|
-
/** Enable SSL/TLS for the target */
|
|
45
|
-
ssl?: boolean;
|
|
46
|
-
/** Remap the URL path before forwarding */
|
|
47
|
-
remap?: (url: string) => string;
|
|
48
|
-
/** Custom CORS configuration */
|
|
49
|
-
cors?: CorsConfig;
|
|
50
|
-
/** Validation function for this route */
|
|
51
|
-
validate?: (info: ConnectionInfo) => Promise<ForwardValidationResult>;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* CORS configuration
|
|
55
|
-
*/
|
|
56
|
-
interface CorsConfig {
|
|
57
|
-
/** Allowed origins (array of strings or '*' for all) */
|
|
58
|
-
origin?: string | string[];
|
|
59
|
-
/** Allowed HTTP methods */
|
|
60
|
-
methods?: string[];
|
|
61
|
-
/** Allowed headers */
|
|
62
|
-
allowedHeaders?: string[];
|
|
63
|
-
/** Exposed headers */
|
|
64
|
-
exposedHeaders?: string[];
|
|
65
|
-
/** Allow credentials */
|
|
66
|
-
credentials?: boolean;
|
|
67
|
-
/** Max age for preflight cache */
|
|
68
|
-
maxAge?: number;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* SSL/TLS certificate configuration
|
|
72
|
-
*/
|
|
73
|
-
interface CertificateConfig {
|
|
74
|
-
/** Path to private key file or key content */
|
|
75
|
-
key: string;
|
|
76
|
-
/** Path to certificate file or cert content */
|
|
77
|
-
cert: string;
|
|
78
|
-
/** Path to CA file or CA content */
|
|
79
|
-
ca?: string;
|
|
80
|
-
/** Allow HTTP/1.1 fallback */
|
|
81
|
-
allowHTTP1?: boolean;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Server configuration
|
|
85
|
-
*/
|
|
86
|
-
interface ServerConfig {
|
|
87
|
-
/** SSL/TLS certificate configuration */
|
|
88
|
-
ssl?: CertificateConfig;
|
|
89
|
-
/** Route configurations mapped by host */
|
|
90
|
-
routes: Record<string, RouteConfig>;
|
|
91
|
-
/** Default CORS configuration */
|
|
92
|
-
cors?: CorsConfig;
|
|
93
|
-
/** Global validation function */
|
|
94
|
-
validate?: (info: ConnectionInfo) => Promise<ForwardValidationResult>;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Proxy configuration manager
|
|
98
|
-
*/
|
|
99
|
-
declare class ProxyConfig {
|
|
100
|
-
private config;
|
|
101
|
-
private sslConfig?;
|
|
102
|
-
constructor(config: ServerConfig);
|
|
103
|
-
/**
|
|
104
|
-
* Initialize SSL configuration
|
|
105
|
-
*/
|
|
106
|
-
private initializeSSL;
|
|
107
|
-
/**
|
|
108
|
-
* Get SSL configuration
|
|
109
|
-
*/
|
|
110
|
-
getSSL(): {
|
|
111
|
-
key: Buffer;
|
|
112
|
-
cert: Buffer;
|
|
113
|
-
ca?: Buffer;
|
|
114
|
-
allowHTTP1?: boolean;
|
|
115
|
-
} | undefined;
|
|
116
|
-
/**
|
|
117
|
-
* Get route configuration for a host
|
|
118
|
-
*/
|
|
119
|
-
getRoute(host: string): RouteConfig | undefined;
|
|
120
|
-
/**
|
|
121
|
-
* Get target for a host
|
|
122
|
-
*/
|
|
123
|
-
getTarget(host: string): {
|
|
124
|
-
target: undefined;
|
|
125
|
-
ssl: undefined;
|
|
126
|
-
remap: undefined;
|
|
127
|
-
} | {
|
|
128
|
-
target: string;
|
|
129
|
-
ssl: {
|
|
130
|
-
key: Buffer;
|
|
131
|
-
cert: Buffer;
|
|
132
|
-
ca?: Buffer;
|
|
133
|
-
allowHTTP1?: boolean;
|
|
134
|
-
} | undefined;
|
|
135
|
-
remap: ((url: string) => string) | undefined;
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Get CORS headers for a request
|
|
139
|
-
*/
|
|
140
|
-
getCorsHeaders(origin: string, host?: string): OutgoingHttpHeaders;
|
|
141
|
-
/**
|
|
142
|
-
* Validate a request
|
|
143
|
-
*/
|
|
144
|
-
validate(info: ConnectionInfo): Promise<ForwardValidationResult>;
|
|
145
|
-
/**
|
|
146
|
-
* Get ports to listen on
|
|
147
|
-
*/
|
|
148
|
-
getPorts(): number[];
|
|
149
|
-
/**
|
|
150
|
-
* Get the full configuration
|
|
151
|
-
*/
|
|
152
|
-
getConfig(): ServerConfig;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Load configuration with cascading priority:
|
|
156
|
-
* 1. Programmatic config (highest priority)
|
|
157
|
-
* 2. Environment variables
|
|
158
|
-
* 3. Config file
|
|
159
|
-
* 4. Defaults (lowest priority)
|
|
160
|
-
*/
|
|
161
|
-
declare function loadConfig(programmaticConfig?: Partial<ServerConfig>): ProxyConfig;
|
|
162
|
-
/**
|
|
163
|
-
* Load configuration from a file (deprecated - use loadConfig instead)
|
|
164
|
-
*/
|
|
165
|
-
declare function loadConfigFromFile(path: string): ProxyConfig;
|
|
166
|
-
/**
|
|
167
|
-
* Load configuration from environment variables (deprecated - use loadConfig instead)
|
|
168
|
-
*/
|
|
169
|
-
declare function loadConfigFromEnv(): ProxyConfig;
|
|
170
|
-
|
|
171
|
-
export { ProxyConfig as P, RequestType as e, loadConfigFromFile as f, loadConfigFromEnv as g, loadConfig as l };
|
|
172
|
-
export type { CorsConfig as C, ForwardValidationResult as F, Router as R, ServerConfig as S, TLSWebSocket as T, WebSocketRouter as W, Streamer as a, RouteConfig as b, CertificateConfig as c, ConnectionInfo as d };
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { OutgoingHttpHeaders, IncomingMessage } from 'node:http';
|
|
2
|
-
import { IncomingHttpHeaders } from 'node:http2';
|
|
3
|
-
import { TLSSocket } from 'node:tls';
|
|
4
|
-
import WebSocket from 'ws';
|
|
5
|
-
|
|
6
|
-
declare enum RequestType {
|
|
7
|
-
API = "api",
|
|
8
|
-
STREAM = "stream",
|
|
9
|
-
WEBSOCKET = "websocket"
|
|
10
|
-
}
|
|
11
|
-
interface TLSWebSocket extends WebSocket {
|
|
12
|
-
_socket: TLSSocket;
|
|
13
|
-
}
|
|
14
|
-
type Router = (req: any, res: any) => void;
|
|
15
|
-
type WebSocketRouter = (req: IncomingMessage, socket: TLSWebSocket, headers: IncomingHttpHeaders) => void;
|
|
16
|
-
type Streamer = (stream: any, headers: any, flags: any) => void;
|
|
17
|
-
interface ForwardValidationResult {
|
|
18
|
-
status: boolean;
|
|
19
|
-
message?: string;
|
|
20
|
-
code?: number;
|
|
21
|
-
headers?: OutgoingHttpHeaders;
|
|
22
|
-
}
|
|
23
|
-
interface ConnectionInfo {
|
|
24
|
-
id: number;
|
|
25
|
-
method: string;
|
|
26
|
-
path: string;
|
|
27
|
-
remoteAddress: string;
|
|
28
|
-
scheme: string;
|
|
29
|
-
authority: string;
|
|
30
|
-
origin: string;
|
|
31
|
-
headers: IncomingHttpHeaders;
|
|
32
|
-
query: URLSearchParams;
|
|
33
|
-
type: RequestType;
|
|
34
|
-
respond: (status: number, headers?: Record<string, string>, body?: string) => void;
|
|
35
|
-
end: (body?: string) => void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Route configuration for a specific domain/host
|
|
40
|
-
*/
|
|
41
|
-
interface RouteConfig {
|
|
42
|
-
/** Target host:port to proxy to */
|
|
43
|
-
target: string;
|
|
44
|
-
/** Enable SSL/TLS for the target */
|
|
45
|
-
ssl?: boolean;
|
|
46
|
-
/** Remap the URL path before forwarding */
|
|
47
|
-
remap?: (url: string) => string;
|
|
48
|
-
/** Custom CORS configuration */
|
|
49
|
-
cors?: CorsConfig;
|
|
50
|
-
/** Validation function for this route */
|
|
51
|
-
validate?: (info: ConnectionInfo) => Promise<ForwardValidationResult>;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* CORS configuration
|
|
55
|
-
*/
|
|
56
|
-
interface CorsConfig {
|
|
57
|
-
/** Allowed origins (array of strings or '*' for all) */
|
|
58
|
-
origin?: string | string[];
|
|
59
|
-
/** Allowed HTTP methods */
|
|
60
|
-
methods?: string[];
|
|
61
|
-
/** Allowed headers */
|
|
62
|
-
allowedHeaders?: string[];
|
|
63
|
-
/** Exposed headers */
|
|
64
|
-
exposedHeaders?: string[];
|
|
65
|
-
/** Allow credentials */
|
|
66
|
-
credentials?: boolean;
|
|
67
|
-
/** Max age for preflight cache */
|
|
68
|
-
maxAge?: number;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* SSL/TLS certificate configuration
|
|
72
|
-
*/
|
|
73
|
-
interface CertificateConfig {
|
|
74
|
-
/** Path to private key file or key content */
|
|
75
|
-
key: string;
|
|
76
|
-
/** Path to certificate file or cert content */
|
|
77
|
-
cert: string;
|
|
78
|
-
/** Path to CA file or CA content */
|
|
79
|
-
ca?: string;
|
|
80
|
-
/** Allow HTTP/1.1 fallback */
|
|
81
|
-
allowHTTP1?: boolean;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Server configuration
|
|
85
|
-
*/
|
|
86
|
-
interface ServerConfig {
|
|
87
|
-
/** SSL/TLS certificate configuration */
|
|
88
|
-
ssl?: CertificateConfig;
|
|
89
|
-
/** Route configurations mapped by host */
|
|
90
|
-
routes: Record<string, RouteConfig>;
|
|
91
|
-
/** Default CORS configuration */
|
|
92
|
-
cors?: CorsConfig;
|
|
93
|
-
/** Global validation function */
|
|
94
|
-
validate?: (info: ConnectionInfo) => Promise<ForwardValidationResult>;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Proxy configuration manager
|
|
98
|
-
*/
|
|
99
|
-
declare class ProxyConfig {
|
|
100
|
-
private config;
|
|
101
|
-
private sslConfig?;
|
|
102
|
-
constructor(config: ServerConfig);
|
|
103
|
-
/**
|
|
104
|
-
* Initialize SSL configuration
|
|
105
|
-
*/
|
|
106
|
-
private initializeSSL;
|
|
107
|
-
/**
|
|
108
|
-
* Get SSL configuration
|
|
109
|
-
*/
|
|
110
|
-
getSSL(): {
|
|
111
|
-
key: Buffer;
|
|
112
|
-
cert: Buffer;
|
|
113
|
-
ca?: Buffer;
|
|
114
|
-
allowHTTP1?: boolean;
|
|
115
|
-
} | undefined;
|
|
116
|
-
/**
|
|
117
|
-
* Get route configuration for a host
|
|
118
|
-
*/
|
|
119
|
-
getRoute(host: string): RouteConfig | undefined;
|
|
120
|
-
/**
|
|
121
|
-
* Get target for a host
|
|
122
|
-
*/
|
|
123
|
-
getTarget(host: string): {
|
|
124
|
-
target: undefined;
|
|
125
|
-
ssl: undefined;
|
|
126
|
-
remap: undefined;
|
|
127
|
-
} | {
|
|
128
|
-
target: string;
|
|
129
|
-
ssl: {
|
|
130
|
-
key: Buffer;
|
|
131
|
-
cert: Buffer;
|
|
132
|
-
ca?: Buffer;
|
|
133
|
-
allowHTTP1?: boolean;
|
|
134
|
-
} | undefined;
|
|
135
|
-
remap: ((url: string) => string) | undefined;
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Get CORS headers for a request
|
|
139
|
-
*/
|
|
140
|
-
getCorsHeaders(origin: string, host?: string): OutgoingHttpHeaders;
|
|
141
|
-
/**
|
|
142
|
-
* Validate a request
|
|
143
|
-
*/
|
|
144
|
-
validate(info: ConnectionInfo): Promise<ForwardValidationResult>;
|
|
145
|
-
/**
|
|
146
|
-
* Get ports to listen on
|
|
147
|
-
*/
|
|
148
|
-
getPorts(): number[];
|
|
149
|
-
/**
|
|
150
|
-
* Get the full configuration
|
|
151
|
-
*/
|
|
152
|
-
getConfig(): ServerConfig;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Initialize the global configuration
|
|
156
|
-
*/
|
|
157
|
-
declare function initConfig(config: ServerConfig): ProxyConfig;
|
|
158
|
-
/**
|
|
159
|
-
* Get the global configuration
|
|
160
|
-
*/
|
|
161
|
-
declare function getConfig(): ProxyConfig;
|
|
162
|
-
/**
|
|
163
|
-
* Load configuration with cascading priority:
|
|
164
|
-
* 1. Programmatic config (highest priority)
|
|
165
|
-
* 2. Environment variables
|
|
166
|
-
* 3. Config file
|
|
167
|
-
* 4. Defaults (lowest priority)
|
|
168
|
-
*/
|
|
169
|
-
declare function loadConfig(programmaticConfig?: Partial<ServerConfig>): ProxyConfig;
|
|
170
|
-
/**
|
|
171
|
-
* Load configuration from a file (deprecated - use loadConfig instead)
|
|
172
|
-
*/
|
|
173
|
-
declare function loadConfigFromFile(path: string): ProxyConfig;
|
|
174
|
-
/**
|
|
175
|
-
* Load configuration from environment variables (deprecated - use loadConfig instead)
|
|
176
|
-
*/
|
|
177
|
-
declare function loadConfigFromEnv(): ProxyConfig;
|
|
178
|
-
|
|
179
|
-
export { ProxyConfig as P, RequestType as e, loadConfigFromFile as f, getConfig as g, loadConfigFromEnv as h, initConfig as i, loadConfig as l };
|
|
180
|
-
export type { CorsConfig as C, ForwardValidationResult as F, Router as R, ServerConfig as S, TLSWebSocket as T, WebSocketRouter as W, Streamer as a, RouteConfig as b, CertificateConfig as c, ConnectionInfo as d };
|