@robiki/proxy 1.0.1 → 1.0.2

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.
@@ -0,0 +1,174 @@
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
+ /** Ports to listen on (defaults to [443, 8080, 9229]) */
96
+ ports?: number[];
97
+ }
98
+ /**
99
+ * Proxy configuration manager
100
+ */
101
+ declare class ProxyConfig {
102
+ private config;
103
+ private sslConfig?;
104
+ constructor(config: ServerConfig);
105
+ /**
106
+ * Initialize SSL configuration
107
+ */
108
+ private initializeSSL;
109
+ /**
110
+ * Get SSL configuration
111
+ */
112
+ getSSL(): {
113
+ key: Buffer;
114
+ cert: Buffer;
115
+ ca?: Buffer;
116
+ allowHTTP1?: boolean;
117
+ } | undefined;
118
+ /**
119
+ * Get route configuration for a host
120
+ */
121
+ getRoute(host: string): RouteConfig | undefined;
122
+ /**
123
+ * Get target for a host
124
+ */
125
+ getTarget(host: string): {
126
+ target: undefined;
127
+ ssl: undefined;
128
+ remap: undefined;
129
+ } | {
130
+ target: string;
131
+ ssl: {
132
+ key: Buffer;
133
+ cert: Buffer;
134
+ ca?: Buffer;
135
+ allowHTTP1?: boolean;
136
+ } | undefined;
137
+ remap: ((url: string) => string) | undefined;
138
+ };
139
+ /**
140
+ * Get CORS headers for a request
141
+ */
142
+ getCorsHeaders(origin: string, host?: string): OutgoingHttpHeaders;
143
+ /**
144
+ * Validate a request
145
+ */
146
+ validate(info: ConnectionInfo): Promise<ForwardValidationResult>;
147
+ /**
148
+ * Get ports to listen on
149
+ */
150
+ getPorts(): number[];
151
+ /**
152
+ * Get the full configuration
153
+ */
154
+ getConfig(): ServerConfig;
155
+ }
156
+ /**
157
+ * Load configuration with cascading priority:
158
+ * 1. Programmatic config (highest priority)
159
+ * 2. Environment variables
160
+ * 3. Config file
161
+ * 4. Defaults (lowest priority)
162
+ */
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;
172
+
173
+ export { ProxyConfig as P, RequestType as e, loadConfigFromFile as f, loadConfigFromEnv as g, loadConfig as l };
174
+ 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-CQ7zIaQt.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-CQ7zIaQt.js';
1
+ import { P as ProxyConfig, T as TLSWebSocket, S as ServerConfig, R as Router, a as Streamer, W as WebSocketRouter } from './config-CeJ1tf8T.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-CeJ1tf8T.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';
@@ -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, g as loadConfigFromEnv, f as loadConfigFromFile } from '../config-CQ7zIaQt.js';
2
+ export { c as CertificateConfig, C as CorsConfig, P as ProxyConfig, b as RouteConfig, S as ServerConfig, l as loadConfig, g as loadConfigFromEnv, f as loadConfigFromFile } from '../config-CeJ1tf8T.js';
3
3
  import 'node:http2';
4
4
  import 'node:tls';
5
5
  import 'ws';
@@ -131,7 +131,7 @@ class ProxyConfig {
131
131
  * Get ports to listen on
132
132
  */
133
133
  getPorts() {
134
- return [443, 8080, 9229];
134
+ return this.config.ports || [443, 8080, 9229];
135
135
  }
136
136
  /**
137
137
  * Get the full configuration
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robiki/proxy",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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",