@robiki/proxy 1.0.0 → 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.
package/README.de.md ADDED
@@ -0,0 +1,639 @@
1
+ # 🚀 Robiki Proxy
2
+
3
+ > Ein leistungsstarker, flexibler HTTP/2-Reverse-Proxy mit WebSocket-Unterstützung, konfigurierbarem Routing, CORS und Anforderungsvalidierung. Verwenden Sie es als npm-Paket in Ihrer Node.js-Anwendung oder als eigenständigen Docker-Container. Nur für die Verwendung als Domain-Proxy in lokalen Entwicklungsumgebungen vorgesehen.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@robiki/proxy.svg)](https://www.npmjs.com/package/@robiki/proxy)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## 🌍 Sprachen / Languages / 语言 / 言語 / Języki / Idiomas / Языки
9
+
10
+ [English](README.md) | [Deutsch](README.de.md) | [中文](README.zh.md) | [日本語](README.ja.md) | [Polski](README.pl.md) | [Español](README.es.md) | [Русский](README.ru.md)
11
+
12
+ ## ✨ Funktionen
13
+
14
+ - **🔒 HTTP/2 & SSL/TLS-Unterstützung**: Vollständige HTTP/2-Protokollunterstützung mit automatischem HTTP/1.1-Fallback
15
+ - **🔌 WebSocket-Proxying**: Nahtlose WebSocket-Verbindungsverarbeitung und -Proxying
16
+ - **🌐 Flexibles Routing**: Routen nach Domain/Host mit Wildcard-Unterstützung konfigurieren
17
+ - **🛡️ CORS-Verwaltung**: Globale und routenspezifische CORS-Konfiguration
18
+ - **✅ Anforderungsvalidierung**: Benutzerdefinierte Validierungslogik für Authentifizierung, Rate Limiting usw.
19
+ - **🔄 URL-Remapping**: URLs vor der Weiterleitung an Zieldienste transformieren
20
+ - **📦 Duale Nutzung**: Als npm-Paket oder Docker-Container verwenden
21
+ - **🎯 Multi-Port-Unterstützung**: Gleichzeitiges Lauschen auf mehreren Ports
22
+ - **⚡ Hohe Leistung**: Basiert auf der nativen HTTP/2-Implementierung von Node.js
23
+
24
+ ## 📦 Installation
25
+
26
+ ### Als npm-Paket
27
+
28
+ ```bash
29
+ npm install @robiki/proxy
30
+ ```
31
+
32
+ ```bash
33
+ yarn add @robiki/proxy
34
+ ```
35
+
36
+ ### Als Docker-Container
37
+
38
+ ```bash
39
+ docker pull robiki/proxy:latest
40
+ ```
41
+
42
+ ### Als Docker Compose Service
43
+
44
+ ```yaml
45
+ services:
46
+ proxy:
47
+ image: robiki/proxy:latest
48
+ container_name: robiki-proxy
49
+ restart: unless-stopped
50
+ ports:
51
+ - '443:443'
52
+ - '8080:8080'
53
+ - '9229:9229'
54
+ volumes:
55
+ - ./proxy.config.json:/app/proxy.config.json:ro
56
+ - ./certs:/app/certs:ro
57
+ networks:
58
+ - app-network
59
+ ```
60
+
61
+ ## Hinweise
62
+
63
+ - Hosts, die lokal konfiguriert sind, sollten zu Ihrer lokalen `hosts`-Datei hinzugefügt werden.
64
+ - Wenn Sie benutzerdefinierte Zertifikate verwenden, müssen Sie die Zertifikatdateien zum `certs`-Verzeichnis hinzufügen.
65
+
66
+ ## 🚀 Schnellstart
67
+
68
+ ### Verwendung als npm-Paket
69
+
70
+ ```javascript
71
+ import { createProxy } from '@robiki/proxy';
72
+
73
+ const proxy = await createProxy({
74
+ ports: [443, 8080],
75
+ ssl: {
76
+ key: './certs/key.pem',
77
+ cert: './certs/cert.pem',
78
+ allowHTTP1: true,
79
+ },
80
+ routes: {
81
+ 'api.example.com': {
82
+ target: 'localhost:3000',
83
+ ssl: true,
84
+ },
85
+ 'example.com': {
86
+ target: 'localhost:8080',
87
+ ssl: false,
88
+ },
89
+ },
90
+ });
91
+
92
+ console.log('Proxy-Server läuft!');
93
+ ```
94
+
95
+ ### Verwendung mit Docker
96
+
97
+ 1. Erstellen Sie eine `proxy.config.json`-Datei:
98
+
99
+ ```json
100
+ {
101
+ "ports": [443, 8080],
102
+ "ssl": {
103
+ "key": "/app/certs/key.pem",
104
+ "cert": "/app/certs/cert.pem",
105
+ "allowHTTP1": true
106
+ },
107
+ "routes": {
108
+ "api.example.com": {
109
+ "target": "backend-service:3000",
110
+ "ssl": true
111
+ },
112
+ "example.com": {
113
+ "target": "frontend-service:8080",
114
+ "ssl": false
115
+ }
116
+ }
117
+ }
118
+ ```
119
+
120
+ 2. Erstellen Sie eine `docker-compose.yml`:
121
+
122
+ ```yaml
123
+ version: '3.8'
124
+
125
+ services:
126
+ proxy:
127
+ image: robiki/proxy:latest
128
+ ports:
129
+ - '443:443'
130
+ - '8080:8080'
131
+ volumes:
132
+ - ./proxy.config.json:/app/proxy.config.json:ro
133
+ - ./certs:/app/certs:ro
134
+ environment:
135
+ - PROXY_CONFIG=/app/proxy.config.json
136
+ networks:
137
+ - app-network
138
+
139
+ backend-service:
140
+ image: your-backend-image
141
+ networks:
142
+ - app-network
143
+
144
+ frontend-service:
145
+ image: your-frontend-image
146
+ networks:
147
+ - app-network
148
+
149
+ networks:
150
+ app-network:
151
+ driver: bridge
152
+ ```
153
+
154
+ 3. Starten Sie die Dienste:
155
+
156
+ ```bash
157
+ docker-compose up -d
158
+ ```
159
+
160
+ ## 📖 Konfiguration
161
+
162
+ ### Konfigurationsdatei
163
+
164
+ Erstellen Sie eine `proxy.config.json`-Datei mit folgender Struktur:
165
+
166
+ ```json
167
+ {
168
+ "ports": [443, 8080],
169
+ "ssl": {
170
+ "key": "./certs/key.pem",
171
+ "cert": "./certs/cert.pem",
172
+ "ca": "./certs/ca.pem",
173
+ "allowHTTP1": true
174
+ },
175
+ "cors": {
176
+ "origin": "*",
177
+ "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
178
+ "allowedHeaders": ["Content-Type", "Authorization"],
179
+ "credentials": true,
180
+ "maxAge": 86400
181
+ },
182
+ "routes": {
183
+ "api.example.com": {
184
+ "target": "backend-service:3000",
185
+ "ssl": true,
186
+ "cors": {
187
+ "origin": ["https://example.com"],
188
+ "credentials": true
189
+ }
190
+ },
191
+ "*.example.com": {
192
+ "target": "wildcard-service:4000",
193
+ "ssl": true
194
+ }
195
+ }
196
+ }
197
+ ```
198
+
199
+ ### Umgebungsvariablen
200
+
201
+ Sie können den Proxy auch über Umgebungsvariablen konfigurieren:
202
+
203
+ ```bash
204
+ # SSL-Konfiguration
205
+ SSL_KEY=/app/certs/key.pem
206
+ SSL_CERT=/app/certs/cert.pem
207
+ SSL_CA=/app/certs/ca.pem
208
+ SSL_ALLOW_HTTP1=true
209
+
210
+ # CORS-Konfiguration
211
+ CORS_ORIGIN=*
212
+ CORS_METHODS=GET,POST,PUT,DELETE,OPTIONS
213
+ CORS_HEADERS=Content-Type,Authorization
214
+ CORS_CREDENTIALS=true
215
+
216
+ # Debug-Modus
217
+ DEBUG=true # Aktiviert detailliertes Logging für Proxy-Verbindungen und Fehler
218
+ ```
219
+
220
+ ## 🎯 Erweiterte Verwendung
221
+
222
+ ### URL-Remapping
223
+
224
+ URLs vor der Weiterleitung an Zieldienste transformieren:
225
+
226
+ ```javascript
227
+ const config = {
228
+ routes: {
229
+ 'api.example.com': {
230
+ target: 'backend:3000',
231
+ ssl: true,
232
+ remap: (url) => {
233
+ // /api-Präfix entfernen
234
+ return url.replace(/^\/api/, '');
235
+ },
236
+ },
237
+ },
238
+ };
239
+ ```
240
+
241
+ ### Anforderungsvalidierung
242
+
243
+ Benutzerdefinierte Validierungslogik für Authentifizierung, Rate Limiting usw. hinzufügen:
244
+
245
+ ```javascript
246
+ const config = {
247
+ // Globale Validierung
248
+ validate: async (info) => {
249
+ if (!info.headers.authorization) {
250
+ return {
251
+ status: false,
252
+ code: 401,
253
+ message: 'Nicht autorisiert',
254
+ headers: { 'www-authenticate': 'Bearer' },
255
+ };
256
+ }
257
+ return { status: true };
258
+ },
259
+ routes: {
260
+ 'api.example.com': {
261
+ target: 'backend:3000',
262
+ ssl: true,
263
+ // Routenspezifische Validierung
264
+ validate: async (info) => {
265
+ const rateLimit = await checkRateLimit(info.remoteAddress);
266
+ if (!rateLimit.allowed) {
267
+ return {
268
+ status: false,
269
+ code: 429,
270
+ message: 'Zu viele Anfragen',
271
+ };
272
+ }
273
+ return { status: true };
274
+ },
275
+ },
276
+ },
277
+ };
278
+ ```
279
+
280
+ ### Benutzerdefinierte CORS-Konfiguration
281
+
282
+ CORS global oder pro Route konfigurieren:
283
+
284
+ ```javascript
285
+ const config = {
286
+ // Globales CORS
287
+ cors: {
288
+ origin: ['https://example.com', 'https://www.example.com'],
289
+ methods: ['GET', 'POST', 'PUT', 'DELETE'],
290
+ allowedHeaders: ['Content-Type', 'Authorization'],
291
+ credentials: true,
292
+ maxAge: 86400,
293
+ },
294
+ routes: {
295
+ 'api.example.com': {
296
+ target: 'backend:3000',
297
+ ssl: true,
298
+ // Routenspezifisches CORS (überschreibt global)
299
+ cors: {
300
+ origin: '*',
301
+ credentials: false,
302
+ },
303
+ },
304
+ },
305
+ };
306
+ ```
307
+
308
+ ### Benutzerdefinierte Handler
309
+
310
+ Benutzerdefinierte Request-Handler für erweiterte Anwendungsfälle erstellen:
311
+
312
+ ```javascript
313
+ import { createCustomProxy } from '@robiki/proxy';
314
+
315
+ const customRestHandler = async (req, res) => {
316
+ if (req.url === '/health') {
317
+ res.writeHead(200, { 'content-type': 'application/json' });
318
+ return res.end(JSON.stringify({ status: 'ok' }));
319
+ }
320
+ // Auf Standard-Proxy-Verhalten zurückfallen
321
+ const { restAPIProxyHandler } = await import('@robiki/proxy/connections');
322
+ return restAPIProxyHandler(req, res);
323
+ };
324
+
325
+ const proxy = await createCustomProxy(config, {
326
+ rest: customRestHandler,
327
+ websocket: customWebSocketHandler,
328
+ stream: customStreamHandler,
329
+ });
330
+ ```
331
+
332
+ ## 🔧 API-Referenz
333
+
334
+ ### `createProxy(config: ServerConfig): Promise<ProxyServer>`
335
+
336
+ Erstellt und startet einen Proxy-Server mit der angegebenen Konfiguration.
337
+
338
+ **Parameter:**
339
+
340
+ - `config`: Server-Konfigurationsobjekt
341
+
342
+ **Rückgabe:** Promise, das zu einer `ProxyServer`-Instanz aufgelöst wird
343
+
344
+ ### `ProxyServer`
345
+
346
+ **Methoden:**
347
+
348
+ - `start()`: Proxy-Server starten
349
+ - `stop()`: Proxy-Server stoppen
350
+ - `getConfig()`: Aktuelle Konfiguration abrufen
351
+
352
+ ### Konfigurationstypen
353
+
354
+ #### `ServerConfig`
355
+
356
+ ```typescript
357
+ interface ServerConfig {
358
+ ports?: number[];
359
+ ssl?: CertificateConfig;
360
+ routes: Record<string, RouteConfig>;
361
+ cors?: CorsConfig;
362
+ validate?: (info: ConnectionInfo) => Promise<ForwardValidationResult>;
363
+ }
364
+ ```
365
+
366
+ #### `RouteConfig`
367
+
368
+ ```typescript
369
+ interface RouteConfig {
370
+ target: string;
371
+ ssl?: boolean;
372
+ remap?: (url: string) => string;
373
+ cors?: CorsConfig;
374
+ validate?: (info: ConnectionInfo) => Promise<ForwardValidationResult>;
375
+ }
376
+ ```
377
+
378
+ #### `CorsConfig`
379
+
380
+ ```typescript
381
+ interface CorsConfig {
382
+ origin?: string | string[];
383
+ methods?: string[];
384
+ allowedHeaders?: string[];
385
+ exposedHeaders?: string[];
386
+ credentials?: boolean;
387
+ maxAge?: number;
388
+ }
389
+ ```
390
+
391
+ #### `ConnectionInfo`
392
+
393
+ ```typescript
394
+ interface ConnectionInfo {
395
+ id: number;
396
+ method: string;
397
+ path: string;
398
+ remoteAddress: string;
399
+ scheme: string;
400
+ authority: string;
401
+ origin: string;
402
+ headers: IncomingHttpHeaders;
403
+ query: URLSearchParams;
404
+ type: RequestType;
405
+ }
406
+ ```
407
+
408
+ ## 🐳 Docker-Verwendung
409
+
410
+ ### Verwendung in einem anderen Projekt
411
+
412
+ 1. Fügen Sie den Proxy zu Ihrer `docker-compose.yml` hinzu:
413
+
414
+ ```yaml
415
+ services:
416
+ proxy:
417
+ image: robiki/proxy:latest
418
+ ports:
419
+ - '443:443'
420
+ - '8080:8080'
421
+ volumes:
422
+ - ./proxy.config.json:/app/proxy.config.json:ro
423
+ - ./certs:/app/certs:ro
424
+ networks:
425
+ - your-network
426
+
427
+ your-service:
428
+ image: your-service-image
429
+ networks:
430
+ - your-network
431
+ ```
432
+
433
+ 2. Konfigurieren Sie Routen in `proxy.config.json`, um auf Ihre Dienste zu verweisen
434
+
435
+ 3. Starten Sie Ihren Stack:
436
+
437
+ ```bash
438
+ docker-compose up -d
439
+ ```
440
+
441
+ ### Benutzerdefiniertes Image erstellen
442
+
443
+ Erstellen Sie ein benutzerdefiniertes Dockerfile:
444
+
445
+ ```dockerfile
446
+ FROM robiki/proxy:latest
447
+
448
+ # Kopieren Sie Ihre Konfiguration
449
+ COPY proxy.config.json /app/proxy.config.json
450
+ COPY certs /app/certs
451
+
452
+ # Umgebungsvariablen setzen
453
+ ENV PROXY_CONFIG=/app/proxy.config.json
454
+ ```
455
+
456
+ ## 📚 Beispiele
457
+
458
+ Weitere Verwendungsbeispiele finden Sie im Verzeichnis `examples/`:
459
+
460
+ - `basic-usage.js` - Einfache Proxy-Einrichtung
461
+ - `advanced-usage.js` - Erweiterte Funktionen (Validierung, CORS, Remapping)
462
+ - `custom-handlers.js` - Benutzerdefinierte Request-Handler
463
+ - `docker-compose.example.yml` - Vollständige Docker-Einrichtung
464
+
465
+ ## 🔐 SSL/TLS-Zertifikate
466
+
467
+ ### Selbstsignierte Zertifikate generieren
468
+
469
+ Für die Entwicklung:
470
+
471
+ ```bash
472
+ mkdir -p certs
473
+ openssl req -x509 -newkey rsa:4096 -keyout certs/key.pem -out certs/cert.pem -days 365 -nodes
474
+ ```
475
+
476
+ ### Let's Encrypt verwenden
477
+
478
+ Für die Produktion verwenden Sie Let's Encrypt-Zertifikate:
479
+
480
+ ```bash
481
+ certbot certonly --standalone -d example.com
482
+ ```
483
+
484
+ Verweisen Sie dann in Ihrer Konfiguration darauf:
485
+
486
+ ```json
487
+ {
488
+ "ssl": {
489
+ "key": "/etc/letsencrypt/live/example.com/privkey.pem",
490
+ "cert": "/etc/letsencrypt/live/example.com/fullchain.pem"
491
+ }
492
+ }
493
+ ```
494
+
495
+ ## 🤝 Mitwirken
496
+
497
+ Beiträge sind willkommen! Bitte zögern Sie nicht, einen Pull Request einzureichen.
498
+
499
+ ## 📄 Lizenz
500
+
501
+ MIT © Robiki sp. z o.o.
502
+
503
+ ## 🔗 Links
504
+
505
+ - [GitHub-Repository](https://github.com/robiki-ai/robiki-proxy)
506
+ - [npm-Paket](https://www.npmjs.com/package/@robiki/proxy)
507
+ - [Issue-Tracker](https://github.com/robiki-ai/robiki-proxy/issues)
508
+
509
+ ## 💡 Anwendungsfälle
510
+
511
+ - **Microservices-Architektur**: Anfragen basierend auf Domain/Pfad an verschiedene Dienste weiterleiten
512
+ - **Entwicklungsumgebung**: Lokaler Proxy zum Testen mehrerer Dienste
513
+ - **API-Gateway**: Zentraler Einstiegspunkt mit Authentifizierung und Rate Limiting
514
+ - **SSL-Terminierung**: SSL/TLS auf Proxy-Ebene verarbeiten
515
+ - **CORS-Verwaltung**: Zentralisierte CORS-Konfiguration
516
+ - **Load Balancing**: Verkehr auf mehrere Instanzen verteilen (mit benutzerdefinierten Handlern)
517
+
518
+ ## 🛠️ Fehlerbehebung
519
+
520
+ ### Debug-Modus
521
+
522
+ Aktivieren Sie detailliertes Logging zur Fehlerbehebung bei Verbindungsproblemen:
523
+
524
+ ```bash
525
+ # Debug-Modus aktivieren
526
+ DEBUG=true node your-proxy-script.js
527
+
528
+ # Oder mit Docker
529
+ docker run -e DEBUG=true robiki/proxy:latest
530
+
531
+ # Oder in docker-compose.yml
532
+ services:
533
+ proxy:
534
+ image: robiki/proxy:latest
535
+ environment:
536
+ - DEBUG=true
537
+ ```
538
+
539
+ Wenn `DEBUG=true`, protokolliert der Proxy:
540
+ - Alle Proxy-Verbindungsversuche (REST, WebSocket, HTTP/2-Streams)
541
+ - Anfrage- und Antwortdetails
542
+ - Verbindungsfehler und Timeouts
543
+ - Proxy-Fehler und Client-Fehler
544
+
545
+ ### Port bereits in Verwendung
546
+
547
+ Der Proxy versucht automatisch, Prozesse auf den konfigurierten Ports zu beenden. Wenn dies fehlschlägt, geben Sie die Ports manuell frei:
548
+
549
+ ```bash
550
+ lsof -ti:443 | xargs kill -9
551
+ lsof -ti:8080 | xargs kill -9
552
+ ```
553
+
554
+ ### SSL-Zertifikatfehler
555
+
556
+ Stellen Sie sicher, dass Ihre Zertifikatdateien lesbar und im richtigen Format (PEM) sind. Verwenden Sie für die Entwicklung selbstsignierte Zertifikate.
557
+
558
+ ### WebSocket-Verbindungsprobleme
559
+
560
+ Stellen Sie sicher, dass Ihre WebSocket-Routen mit dem richtigen Protokoll (ws/wss) konfiguriert sind und dass der Zieldienst WebSocket-Verbindungen unterstützt.
561
+
562
+ ## 🧪 Testen
563
+
564
+ Robiki Proxy enthält eine umfassende Testsuite mit Unit-Tests, Integrationstests und erweiterten Szenarien.
565
+
566
+ ### Tests ausführen
567
+
568
+ ```bash
569
+ # Alle Tests ausführen
570
+ yarn test
571
+
572
+ # Tests im Watch-Modus ausführen
573
+ yarn test:watch
574
+
575
+ # Tests mit Coverage ausführen
576
+ yarn test:coverage
577
+
578
+ # Tests mit UI ausführen
579
+ yarn test:ui
580
+ ```
581
+
582
+ ### Test-Coverage
583
+
584
+ Die Testsuite umfasst:
585
+
586
+ - **Unit-Tests**: Konfiguration, Utilities, Header-Konvertierung, CORS-Behandlung
587
+ - **Integrationstests**: HTTP-Proxying, Routenauflösung, Validierung, Config-Loading
588
+ - **Erweiterte Tests**: WebSocket-Proxying, HTTP/2-Streams, gleichzeitige Verbindungen
589
+ - **Docker-Tests**: Container-Builds, Config-Loading, Laufzeitverhalten
590
+
591
+ ### Docker-Tests
592
+
593
+ Docker-Integrationstests ausführen:
594
+
595
+ ```bash
596
+ # Vollständiger Docker-Integrationstest
597
+ yarn test:docker
598
+
599
+ # Config-Loading spezifisch testen
600
+ yarn test:docker:config
601
+
602
+ # Alle Tests ausführen (Unit + Integration + Docker)
603
+ yarn test:all
604
+ ```
605
+
606
+ Oder mit Make:
607
+
608
+ ```bash
609
+ # Schneller Docker-Build-Test
610
+ make test-docker
611
+
612
+ # Vollständige Integrationstestsuite
613
+ make test-docker-full
614
+
615
+ # Config-Loading-Test
616
+ make test-docker-config
617
+
618
+ # Docker Compose-Test
619
+ make test-docker-compose
620
+ ```
621
+
622
+ Weitere Details finden Sie im [Docker Tests README](tests/docker/README.md).
623
+
624
+ ## 📊 Leistung
625
+
626
+ Der Proxy basiert auf der nativen HTTP/2-Implementierung von Node.js und ist für hohe Leistung konzipiert:
627
+
628
+ - Effiziente Stream-Verarbeitung
629
+ - Minimaler Overhead
630
+ - Connection Pooling
631
+ - Automatischer HTTP/1.1-Fallback
632
+
633
+ Für Produktionsbereitstellungen berücksichtigen Sie:
634
+
635
+ - Verwendung eines Prozessmanagers (PM2, systemd)
636
+ - Aktivierung von Clustering für Multi-Core-Systeme
637
+ - Überwachung mit Health Checks
638
+ - Einrichtung eines ordnungsgemäßen Loggings
639
+