worker-lb 0.0.2 → 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 +6 -0
- package/package.json +1 -1
- package/src/index.ts +2 -2
package/README.md
CHANGED
|
@@ -15,3 +15,9 @@ worker-lb is a small and extensible load balancer built on Cloudflare Workers. I
|
|
|
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
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
|
-
(
|
|
203
|
+
(attemptStart - startTime).toString(),
|
|
204
204
|
);
|
|
205
205
|
|
|
206
206
|
return new Response(response.body, {
|