dynamic-self-register-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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/proxy.js +18 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynamic-self-register-proxy",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Dynamic reverse proxy with self-registration API - applications can register themselves and receive an automatically assigned port",
5
5
  "main": "proxy-client.js",
6
6
  "bin": {
package/proxy.js CHANGED
@@ -401,6 +401,7 @@ app.get('/proxy/health', (req, res) => {
401
401
  /**
402
402
  * GET /
403
403
  * Page d'accueil listant tous les serveurs disponibles
404
+ * Retourne du JSON si le client l'accepte (API), sinon du HTML (navigateur)
404
405
  */
405
406
  app.get('/', (req, res) => {
406
407
  const routes = [];
@@ -409,13 +410,29 @@ app.get('/', (req, res) => {
409
410
  path,
410
411
  port: value.port,
411
412
  name: value.name,
412
- registeredAt: value.registeredAt
413
+ registeredAt: value.registeredAt,
414
+ target: `http://localhost:${value.port}`
413
415
  });
414
416
  });
415
417
 
416
418
  // Tri par nom
417
419
  routes.sort((a, b) => a.name.localeCompare(b.name));
418
420
 
421
+ // Si le client accepte JSON (et pas spécifiquement HTML), retourne du JSON
422
+ const acceptHeader = req.get('Accept') || '';
423
+ const wantsJson = acceptHeader.includes('application/json') ||
424
+ (acceptHeader.includes('*/*') && !acceptHeader.includes('text/html'));
425
+
426
+ if (wantsJson) {
427
+ return res.json({
428
+ status: 'healthy',
429
+ uptime: process.uptime(),
430
+ count: routes.length,
431
+ routes,
432
+ availablePorts: (INTERNAL_PORT_END - INTERNAL_PORT_START) - registry.usedPorts.size
433
+ });
434
+ }
435
+
419
436
  const html = `
420
437
  <!DOCTYPE html>
421
438
  <html lang="fr">