@infodb/revx 0.2.2 → 1.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.
package/README.md CHANGED
@@ -1,60 +1,124 @@
1
1
  # @infodb/revx
2
2
 
3
- Reverse proxy CLI tool with YAML configuration. Built with Express and http-proxy-middleware.
3
+ **Host multiple Vite projects on a single port with unified routing.**
4
+
5
+ Perfect for monorepo development - run all your Vite apps, backend APIs, and other dev servers together with native HMR support.
6
+
7
+ ## Why revx?
8
+
9
+ Development in a monorepo with multiple Vite projects is painful:
10
+ - Each Vite app runs on a different port (3000, 3001, 3002...)
11
+ - Cross-app navigation requires hardcoded ports
12
+ - Cookie/session sharing is complicated
13
+ - CORS issues everywhere
14
+
15
+ **revx solves this** by using Vite's middleware mode to host everything on one port with path-based routing:
16
+
17
+ ```
18
+ http://localhost:3000/app1 → Vite Project 1 (native HMR)
19
+ http://localhost:3000/app2 → Vite Project 2 (native HMR)
20
+ http://localhost:3000/api → Your Backend API
21
+ http://localhost:3000/legacy → webpack dev server (via proxy)
22
+ ```
4
23
 
5
24
  ## Features
6
25
 
7
- - YAML-based configuration
8
- - Simple reverse proxy setup
9
- - **Automatic route sorting** - Routes are automatically sorted by specificity (longest paths first)
10
- - Load balancing (Round-robin, Random, IP-hash)
11
- - WebSocket support
12
- - Request/Response header transformation
13
- - CORS configuration
14
- - SSL/TLS support
15
- - Health checks
16
- - Request ID tracking
17
- - Environment variable expansion
26
+ - **🎯 Primary: Multi-Vite hosting** - Native Vite integration with full HMR support
27
+ - **🔌 Reverse proxy** - Integrate webpack, Parcel, or any other dev server
28
+ - **📁 Static file serving** - Serve built assets or documentation
29
+ - **🎨 YAML configuration** - Simple, declarative routing
30
+ - **⚡ Automatic route sorting** - Routes prioritized by specificity
31
+ - **🌐 CORS & environment variables** - Full control over cross-origin and config
18
32
 
19
33
  ## Installation
20
34
 
35
+ ### Option 1: Install as dev dependency (Recommended)
36
+
37
+ ```bash
38
+ npm install -D @infodb/revx
39
+ # or
40
+ pnpm add -D @infodb/revx
41
+ ```
42
+
43
+ Then add to package.json scripts:
44
+ ```json
45
+ {
46
+ "scripts": {
47
+ "dev": "revx start",
48
+ "dev:verbose": "revx start --verbose"
49
+ }
50
+ }
51
+ ```
52
+
53
+ ### Option 2: Use with npx/pnpx (No installation)
54
+
55
+ ```bash
56
+ npx @infodb/revx start
57
+ # or
58
+ pnpx @infodb/revx start
59
+ ```
60
+
61
+ Good for trying out revx, but slower on repeated runs.
62
+
63
+ ### Option 3: Global installation
64
+
21
65
  ```bash
22
66
  npm install -g @infodb/revx
23
67
  # or
24
68
  pnpm add -g @infodb/revx
25
- # or
26
- npx @infodb/revx
27
69
  ```
28
70
 
29
71
  ## Quick Start
30
72
 
31
- 1. Create a configuration file:
73
+ 1. Install revx in your monorepo:
32
74
 
33
75
  ```bash
34
- revx init
76
+ pnpm add -D @infodb/revx
77
+ ```
78
+
79
+ 2. Create a configuration file:
80
+
81
+ ```bash
82
+ pnpm revx init
35
83
  ```
36
84
 
37
- This creates a `revx.yaml` file with example configuration.
85
+ This creates a `revx.yaml` file with Vite multi-project configuration.
38
86
 
39
- 2. Edit `revx.yaml` to configure your routes:
87
+ 3. Edit `revx.yaml` to point to your Vite projects:
40
88
 
41
89
  ```yaml
42
90
  server:
43
91
  port: 3000
92
+ maxSockets: 512 # Important for Vite performance
44
93
 
45
94
  routes:
95
+ # Your Vite apps
96
+ - path: "/app1"
97
+ vite:
98
+ root: "./apps/app1"
99
+ base: "/app1"
100
+
101
+ - path: "/app2"
102
+ vite:
103
+ root: "./apps/app2"
104
+ base: "/app2"
105
+
106
+ # Backend API
46
107
  - path: "/api/*"
47
108
  target: "http://localhost:4000"
48
109
  pathRewrite:
49
110
  "^/api": ""
50
111
  ```
51
112
 
52
- 3. Start the proxy server:
113
+ 4. Start the unified dev server:
53
114
 
54
115
  ```bash
55
- revx start
116
+ pnpm revx start
117
+ # or add to package.json scripts and run: pnpm dev
56
118
  ```
57
119
 
120
+ Now all your apps are available at `http://localhost:3000` with full HMR! 🎉
121
+
58
122
  ## Commands
59
123
 
60
124
  ### `revx start [config-file]`
@@ -119,8 +183,6 @@ routes:
119
183
 
120
184
  ```yaml
121
185
  global:
122
- timeout: 30000
123
-
124
186
  # Max concurrent sockets (default: 256)
125
187
  # Increase for better performance with dev servers like Vite
126
188
  maxSockets: 512
@@ -134,7 +196,6 @@ global:
134
196
  logging:
135
197
  enabled: true
136
198
  format: "combined" # combined | dev | common | short | tiny
137
- level: "info" # error | warn | info | debug
138
199
  ```
139
200
 
140
201
  ### Performance Tuning
@@ -196,22 +257,50 @@ routes:
196
257
  "^/api": ""
197
258
  ```
198
259
 
199
- #### Load Balancing
260
+ #### Vite Middleware (NEW!)
261
+
262
+ Native Vite integration using middleware mode - the best way to serve multiple Vite projects:
200
263
 
201
264
  ```yaml
202
265
  routes:
203
- - path: "/balanced/*"
204
- targets:
205
- - "http://server1.example.com"
206
- - "http://server2.example.com"
207
- - "http://server3.example.com"
208
- strategy: "round-robin" # round-robin | random | ip-hash
209
- pathRewrite:
210
- "^/balanced": ""
266
+ - path: "/app1"
267
+ vite:
268
+ root: "./projects/app1"
269
+ base: "/app1"
270
+ configFile: "./projects/app1/vite.config.ts" # optional
271
+ ```
272
+
273
+ **Why use Vite middleware instead of proxy?**
274
+ - Full HMR support without WebSocket configuration
275
+ - No proxy overhead - native Vite performance
276
+ - Multiple Vite projects on a single port
277
+ - Better error messages and development experience
278
+
279
+ **Requirements:**
280
+ - Vite must be installed: `npm install vite` or `pnpm add vite`
281
+ - Each Vite project must have its own directory with a valid configuration
282
+
283
+ **Multiple Vite projects example:**
284
+ ```yaml
285
+ routes:
286
+ - path: "/dashboard"
287
+ vite:
288
+ root: "./apps/dashboard"
289
+ base: "/dashboard"
290
+
291
+ - path: "/admin"
292
+ vite:
293
+ root: "./apps/admin"
294
+ base: "/admin"
295
+
296
+ - path: "/api/*"
297
+ target: "http://localhost:4000"
211
298
  ```
212
299
 
213
300
  #### WebSocket Proxy
214
301
 
302
+ WebSocket support is critical for Hot Module Replacement (HMR) with development servers like Vite:
303
+
215
304
  ```yaml
216
305
  routes:
217
306
  - path: "/ws"
@@ -220,64 +309,41 @@ routes:
220
309
  changeOrigin: true
221
310
  ```
222
311
 
223
- #### Header Transformation
312
+ #### Static File Serving
224
313
 
225
- ```yaml
226
- routes:
227
- - path: "/transform/*"
228
- target: "http://backend.example.com"
229
- transform:
230
- request:
231
- headers:
232
- add:
233
- X-API-Version: "v2"
234
- X-Custom-Header: "value"
235
- remove:
236
- - "Cookie"
237
- response:
238
- headers:
239
- add:
240
- X-Proxy-Server: "revx"
241
- remove:
242
- - "Server"
243
- ```
244
-
245
- #### Custom Options
314
+ Serve static files directly without proxying (useful for `vite build --watch` output):
246
315
 
247
316
  ```yaml
248
317
  routes:
249
- - path: "/api/*"
250
- target: "http://api.example.com"
251
- options:
252
- timeout: 5000
253
- followRedirects: true
254
- headers:
255
- X-Forwarded-Host: "${HOST}"
318
+ - path: "/*"
319
+ static: "./dist"
256
320
  ```
257
321
 
258
- ### Middleware
259
-
322
+ **Combined with API proxy:**
260
323
  ```yaml
261
- middleware:
262
- - type: "requestId"
263
- enabled: true
264
- headerName: "X-Request-ID"
324
+ routes:
325
+ # API requests go to backend
326
+ - path: "/api/*"
327
+ target: "http://localhost:4000"
328
+ pathRewrite:
329
+ "^/api": ""
265
330
 
266
- - type: "compression"
267
- enabled: true
268
- threshold: 1024
331
+ # Static files from Vite build
332
+ - path: "/*"
333
+ static: "./dist"
269
334
  ```
270
335
 
271
- ### SSL/TLS
336
+ **Use case: Vite build --watch**
337
+ ```bash
338
+ # Terminal 1: Run Vite in build watch mode
339
+ vite build --watch
272
340
 
273
- ```yaml
274
- ssl:
275
- enabled: true
276
- key: "/path/to/private.key"
277
- cert: "/path/to/certificate.crt"
278
- ca: "/path/to/ca.crt" # Optional
341
+ # Terminal 2: Run revx to serve the built files
342
+ revx start
279
343
  ```
280
344
 
345
+ This serves pre-built static files, avoiding proxy-related errors that can occur with Vite dev server.
346
+
281
347
  ### Environment Variables
282
348
 
283
349
  Use `${VARIABLE_NAME}` syntax to reference environment variables:
@@ -289,15 +355,12 @@ server:
289
355
  routes:
290
356
  - path: "/api/*"
291
357
  target: "${API_URL}"
292
- options:
293
- headers:
294
- Authorization: "Bearer ${API_TOKEN}"
295
358
  ```
296
359
 
297
360
  Then run:
298
361
 
299
362
  ```bash
300
- PORT=3000 API_URL=http://api.example.com API_TOKEN=secret revx start
363
+ PORT=3000 API_URL=http://api.example.com revx start
301
364
  ```
302
365
 
303
366
  ## Examples
@@ -371,62 +434,195 @@ routes:
371
434
  # Proxy everything else to Vite dev server
372
435
  - path: "/*"
373
436
  target: "http://localhost:5173"
374
- ws: true
437
+ ws: true # Enable WebSocket for HMR
375
438
  changeOrigin: true
376
439
  ```
377
440
 
378
- ### Production Load Balancer
441
+ ### Multi-Vite Project Setup (Recommended)
379
442
 
380
443
  ```yaml
381
444
  server:
382
- port: 443
383
- name: "Production Load Balancer"
445
+ port: 3000
446
+ name: "Multi-App Dev Server"
447
+ maxSockets: 512
384
448
 
385
- ssl:
386
- enabled: true
387
- key: "/etc/ssl/private/server.key"
388
- cert: "/etc/ssl/certs/server.crt"
449
+ global:
450
+ cors:
451
+ enabled: true
452
+ origin: "*"
453
+
454
+ routes:
455
+ # App 1 - Customer Portal (Vite)
456
+ - path: "/portal"
457
+ vite:
458
+ root: "./apps/portal"
459
+ base: "/portal"
460
+
461
+ # App 2 - Admin Dashboard (Vite)
462
+ - path: "/admin"
463
+ vite:
464
+ root: "./apps/admin"
465
+ base: "/admin"
466
+
467
+ # Shared API backend
468
+ - path: "/api/*"
469
+ target: "http://localhost:4000"
470
+ pathRewrite:
471
+ "^/api": ""
472
+ ```
473
+
474
+ This setup allows you to:
475
+ - Run multiple Vite projects on one port
476
+ - Share a single backend API across all apps
477
+ - Get full HMR support for all apps
478
+ - Develop in a monorepo-friendly way
479
+
480
+ ### Mixed Development Servers (Vite + webpack)
481
+
482
+ Migrate gradually or mix different build tools:
483
+
484
+ ```yaml
485
+ server:
486
+ port: 3000
487
+ maxSockets: 512
488
+
489
+ routes:
490
+ # New app - using Vite
491
+ - path: "/new-app"
492
+ vite:
493
+ root: "./apps/new-app"
494
+ base: "/new-app"
495
+
496
+ # Legacy app - still on webpack dev server
497
+ - path: "/legacy/*"
498
+ target: "http://localhost:8080"
499
+ ws: true # Enable WebSocket for webpack HMR
500
+ changeOrigin: true
501
+
502
+ # Another legacy app - using Parcel
503
+ - path: "/old-dashboard/*"
504
+ target: "http://localhost:1234"
505
+ ws: true
506
+ changeOrigin: true
507
+
508
+ # Backend API
509
+ - path: "/api/*"
510
+ target: "http://localhost:4000"
511
+ pathRewrite:
512
+ "^/api": ""
513
+
514
+ # Static documentation
515
+ - path: "/docs"
516
+ static: "./public/docs"
517
+ ```
518
+
519
+ **Usage:**
520
+ ```bash
521
+ # Terminal 1: Start webpack dev server
522
+ cd apps/legacy && npm run dev # runs on :8080
523
+
524
+ # Terminal 2: Start Parcel
525
+ cd apps/old-dashboard && npm run dev # runs on :1234
526
+
527
+ # Terminal 3: Start backend
528
+ cd api && npm run dev # runs on :4000
529
+
530
+ # Terminal 4: Start revx (unifies everything)
531
+ npx revx start
532
+ ```
533
+
534
+ Now access everything at `http://localhost:3000`:
535
+ - `/new-app` - Vite with native HMR ⚡
536
+ - `/legacy` - webpack via proxy 🔌
537
+ - `/old-dashboard` - Parcel via proxy 🔌
538
+ - `/api` - Backend API 🔌
539
+ - `/docs` - Static files 📁
540
+
541
+ ### Vite Build Watch Mode
542
+
543
+ ```yaml
544
+ server:
545
+ port: 3000
389
546
 
390
547
  routes:
548
+ # Proxy API requests to backend
549
+ - path: "/api/*"
550
+ target: "http://localhost:4000"
551
+ pathRewrite:
552
+ "^/api": ""
553
+
554
+ # Serve static files built by Vite
391
555
  - path: "/*"
392
- targets:
393
- - "http://app-server-1:8080"
394
- - "http://app-server-2:8080"
395
- - "http://app-server-3:8080"
396
- strategy: "round-robin"
397
- healthCheck:
398
- enabled: true
399
- interval: 30000
400
- path: "/health"
401
- timeout: 3000
556
+ static: "./dist"
557
+ ```
558
+
559
+ Run with:
560
+ ```bash
561
+ # Terminal 1: Build and watch
562
+ vite build --watch
563
+
564
+ # Terminal 2: Serve with revx
565
+ revx start
402
566
  ```
403
567
 
404
568
  ## Troubleshooting
405
569
 
406
- ### CONTENT_LENGTH_MISMATCH Error
570
+ ### When to use each route type?
571
+
572
+ **Vite middleware (`vite` config) - RECOMMENDED for Vite projects:**
573
+ ```yaml
574
+ - path: "/app"
575
+ vite:
576
+ root: "./apps/myapp"
577
+ ```
578
+ - ✅ Best for: Your own Vite projects in the monorepo
579
+ - ✅ Native HMR with no configuration
580
+ - ✅ No proxy overhead
581
+ - ✅ Full Vite dev server features
582
+
583
+ **Reverse proxy (`target` config) - For external/non-Vite servers:**
584
+ ```yaml
585
+ - path: "/legacy"
586
+ target: "http://localhost:8080"
587
+ ws: true
588
+ ```
589
+ - ✅ Best for: webpack, Parcel, external APIs, legacy apps
590
+ - ✅ Preserve HMR via WebSocket proxy
591
+ - ✅ Don't need to modify the target server
592
+
593
+ **Static files (`static` config) - For built assets:**
594
+ ```yaml
595
+ - path: "/docs"
596
+ static: "./dist"
597
+ ```
598
+ - ✅ Best for: Documentation, pre-built assets, `vite build --watch` output
599
+ - ✅ No processing overhead
600
+ - ✅ Production-like serving
407
601
 
408
- The proxy automatically handles `CONTENT_LENGTH_MISMATCH` errors (common with Vite dev server) by:
602
+ ### Common Issues
409
603
 
410
- - **Silently ignoring these errors** in the error handler
411
- - CONTENT_LENGTH_MISMATCH errors are typically benign with streaming responses
412
- - The content is usually already successfully delivered to the client
604
+ **Error: "Vite root directory not found"**
605
+ - Check that the `root` path in your config exists
606
+ - Use relative paths from where you run `revx start`
607
+ - Example: If config is in project root, use `./apps/myapp` not `/apps/myapp`
413
608
 
414
- This is especially important for Vite, which dynamically transforms content (ESM conversion, HMR, etc.), causing the actual response size to differ from the original Content-Length header.
609
+ **Multiple Vite servers slow to start**
610
+ - This is normal - each Vite server initializes independently
611
+ - Use `--verbose` to see progress
612
+ - First startup is slower (dependency pre-bundling)
415
613
 
416
- **Technical details:**
417
- - The error handler checks for `CONTENT_LENGTH_MISMATCH` in error messages
418
- - These errors are logged only in verbose mode and don't interrupt the response
419
- - The response has usually completed successfully before the error is detected
420
- - Works transparently without configuration needed
614
+ **HMR not working for proxied webpack app**
615
+ - Make sure `ws: true` is set in the route config
616
+ - Check that the webpack dev server is actually running
617
+ - Verify WebSocket connection in browser dev tools
618
+ - No additional webpack configuration needed - revx handles WebSocket upgrade automatically
421
619
 
422
- **Why this works:**
423
- - Vite sends Content-Length based on original file size
424
- - Vite then transforms the content (ESM imports, HMR injection)
425
- - The transformed content has a different size
426
- - By the time the mismatch is detected, the client has already received the content
427
- - Ignoring the error prevents unnecessary 502 responses
620
+ **Does webpack need special configuration?**
621
+ - No! Just add `ws: true` in revx config
622
+ - revx automatically handles WebSocket upgrade requests
623
+ - Your existing webpack dev server config works as-is
428
624
 
429
- ### Performance Issues with Vite or Dev Servers
625
+ ### Performance Issues with Dev Servers
430
626
 
431
627
  If you experience slow loading or timeouts when proxying to Vite or similar dev servers:
432
628
 
@@ -454,7 +650,7 @@ If you experience slow loading or timeouts when proxying to Vite or similar dev
454
650
  - Only use `pathRewrite` when you need to modify the path
455
651
 
456
652
  **Q: CORS errors**
457
- - Enable CORS in global config or per-route
653
+ - Enable CORS in global config
458
654
  - Check the `origin` setting matches your client URL
459
655
 
460
656
  ## Development
@@ -1,5 +1,6 @@
1
1
  export declare function initCommand(options: {
2
2
  simple?: boolean;
3
+ proxy?: boolean;
3
4
  output?: string;
4
5
  verbose?: boolean;
5
6
  }): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AA4HA,wBAAsB,WAAW,CAAC,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,iBAwBlG"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAuHA,wBAAsB,WAAW,CAAC,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,iBAiCnH"}