worker-lb 0.0.1 → 0.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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # worker-lb
2
2
 
3
3
  > [!NOTE]
4
- > **WARNING:** I don't know if you should use this in production just yet, this is more of an experiment and by no means is battle-tested.
4
+ > I don't know if you should use this in production just yet, this is more of an experiment and by no means is battle-tested.
5
5
 
6
6
  worker-lb is a small and extensible load balancer built on Cloudflare Workers. It's basically a poor mans Cloudflare Load Balancer, but running on Cloudflare Workers, because why not.
7
7
 
@@ -9,9 +9,15 @@ worker-lb is a small and extensible load balancer built on Cloudflare Workers. I
9
9
 
10
10
  - Failover between multiple HTTP endpoints
11
11
  - Health checks with customizable intervals and timeouts
12
- - "Dooms-day mode" to automatically dump traffic to a log file when all backends are down (not finished yet)
12
+ - Recovery function to dump requests that did not reach any healthy endpoints.
13
13
 
14
14
  ## Use Cases
15
15
 
16
16
  - Simple load balancing for dirty small projects
17
17
  - Latency is not a concern but reliability is
18
+
19
+ ## Headers Added to Requests
20
+
21
+ - `X-Load-Balancer-Endpoint`: The endpoint that served the request
22
+ - `X-Load-Balancer-Latency`: The latency of the request in milliseconds
23
+ - `X-Load-Balancer-Endpoint-Gather-Latency`: The latency of gathering the healthy endpoint in milliseconds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worker-lb",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -8,9 +8,6 @@
8
8
  "files": [
9
9
  "src/index.ts"
10
10
  ],
11
- "scripts": {
12
- "publish": "bun publish"
13
- },
14
11
  "exports": {
15
12
  ".": {
16
13
  "import": "./src/index.ts",
package/src/index.ts CHANGED
@@ -171,10 +171,10 @@ export class LoadBalancer {
171
171
  async handleRequest(request: Request): Promise<Response> {
172
172
  const startTime = Date.now();
173
173
  const endpointsToTry = await this.getEndpointsToTry();
174
- const gatherEndpointLatency = Date.now();
175
174
  const url = new URL(request.url);
176
175
 
177
176
  for (const endpoint of endpointsToTry) {
177
+ const attemptStart = Date.now();
178
178
  try {
179
179
  const targetUrl = endpoint + url.pathname + url.search;
180
180
  const response = await fetch(targetUrl, {
@@ -200,7 +200,7 @@ export class LoadBalancer {
200
200
  );
201
201
  headers.set(
202
202
  "X-Load-Balancer-Endpoint-Gather-Latency",
203
- (gatherEndpointLatency - startTime).toString(),
203
+ (attemptStart - startTime).toString(),
204
204
  );
205
205
 
206
206
  return new Response(response.body, {