smart-stick-loadbalancer 1.0.2 → 1.0.4

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/README.md +60 -15
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # Smart Stick Load Balancer
2
2
 
3
- A lightweight **sticky-session load balancer** for Node.js. It distributes requests to multiple backends, supports sticky sessions via cookies, performs health checks, and can optionally send email alerts.
3
+ A lightweight **sticky-session load balancer** for Node.js. It distributes requests to multiple backends, supports sticky sessions via cookies, performs health checks, and can optionally send email alerts.
4
4
 
5
5
  ---
6
6
 
7
7
  ## Features
8
8
 
9
- - Sticky sessions via cookies
10
- - Health checks with automatic failover
11
- - Optional email alerts
12
- - WebSocket and HTTP support
13
- - Minimal setup
9
+ - Sticky sessions via cookies
10
+ - Health checks with automatic failover
11
+ - Optional email alerts
12
+ - WebSocket and HTTP support
13
+ - Minimal setup
14
14
 
15
15
  ---
16
16
 
@@ -28,8 +28,18 @@ npm install smart-stick-loadbalancer
28
28
  {
29
29
  "port": 3001,
30
30
  "backends": [
31
- { "id": 0, "url": "http://localhost:5000", "owner": "example@example.com", "weight": 1 },
32
- { "id": 1, "url": "http://localhost:5001", "owner": "example@example.com", "weight": 1 }
31
+ {
32
+ "id": 0,
33
+ "url": "http://localhost:5000",
34
+ "owner": "example@example.com",
35
+ "weight": 1
36
+ },
37
+ {
38
+ "id": 1,
39
+ "url": "http://localhost:5001",
40
+ "owner": "example@example.com",
41
+ "weight": 1
42
+ }
33
43
  ],
34
44
  "health": { "interval": 10000, "timeout": 2000 },
35
45
  "email": {
@@ -44,19 +54,54 @@ npm install smart-stick-loadbalancer
44
54
  ## Usage
45
55
 
46
56
  ```js
47
- const { createStickyProxy } = require('smart-stick-loadbalancer');
48
- const config = require('./config.json');
57
+ const { createStickyProxy } = require("smart-stick-loadbalancer");
58
+ const config = require("./config.json");
49
59
 
50
60
  const lb = createStickyProxy(config);
51
61
  lb.start(); // starts the load balancer
52
62
  ```
53
63
 
54
- - Requests to `http://localhost:3001` will be forwarded to the backends.
55
- - Sticky sessions are automatically managed using cookies.
56
- - Health checks run periodically and remove unhealthy backends from rotation.
64
+ - Requests to `http://localhost:3001` will be forwarded to the backends.
65
+ - Sticky sessions are automatically managed using cookies.
66
+ - Health checks run periodically and remove unhealthy backends from rotation.
57
67
 
58
68
  ---
59
69
 
70
+ ## Quick Start Demo
71
+
72
+ Create two simple backend servers:
73
+
74
+ // server5000.js
75
+ ```
76
+ const express = require('express');
77
+ const app = express();
78
+ app.get('/', (req, res) => res.send('Hello from 5000'));
79
+ app.listen(5000, () => console.log('Server 5000 running'));
80
+ ```
81
+
82
+ // server5001.js
83
+ ```
84
+ const express = require('express');
85
+ const app = express();
86
+ app.get('/', (req, res) => res.send('Hello from 5001'));
87
+ app.listen(5001, () => console.log('Server 5001 running'));
88
+ ```
89
+
90
+ Start the load balancer:
91
+
92
+ ```
93
+ node index.js
94
+ ```
95
+
96
+ Open in browser: http://localhost:3001
97
+ Requests should alternate between the two backends (sticky sessions maintained per client).
98
+
99
+ Check health status:
100
+
101
+ ```
102
+ curl http://localhost:3001/_lb/health
103
+ ```
104
+
60
105
  ## Health Endpoint
61
106
 
62
107
  ```http
@@ -82,8 +127,8 @@ Response example:
82
127
 
83
128
  ## Email Alerts
84
129
 
85
- - Alerts are sent when a backend goes down or comes back up.
86
- - Requires valid Gmail credentials (or any supported email service).
130
+ - Alerts are sent when a backend goes down or comes back up.
131
+ - Requires valid Gmail credentials (or any supported email service).
87
132
 
88
133
  ---
89
134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-stick-loadbalancer",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A lightweight sticky-session load balancer for Node.js with health checks and optional email alerts.",
5
5
  "main": "src/index.js",
6
6
  "bin": {