Skip to content

Commit 5305c9b

Browse files
WC-3584 Add eyeball routing config
Provided via a new optional param binding. When provided, it contains info about free tier limiting for this account.
1 parent 13a8aea commit 5305c9b

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

packages/workers-shared/router-worker/src/configuration.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import type { RouterConfig } from "../../utils/types";
1+
import type { EyeballRouterConfig, RouterConfig } from "../../utils/types";
22

3-
export const applyConfigurationDefaults = (
3+
type RequiredEyeballRouterConfig = Required<Exclude<EyeballRouterConfig, null>>;
4+
5+
export const applyRouterConfigDefaults = (
46
configuration?: RouterConfig
57
): Required<RouterConfig> => {
68
return {
@@ -15,3 +17,11 @@ export const applyConfigurationDefaults = (
1517
},
1618
};
1719
};
20+
21+
export const applyEyeballConfigDefaults = (
22+
eyeballConfiguration?: EyeballRouterConfig
23+
): RequiredEyeballRouterConfig => {
24+
return {
25+
limitedAssetsOnly: eyeballConfiguration?.limitedAssetsOnly ?? false,
26+
};
27+
};

packages/workers-shared/router-worker/src/worker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { PerformanceTimer } from "../../utils/performance";
33
import { setupSentry } from "../../utils/sentry";
44
import { mockJaegerBinding } from "../../utils/tracing";
55
import { Analytics, DISPATCH_TYPE, STATIC_ROUTING_DECISION } from "./analytics";
6-
import { applyConfigurationDefaults } from "./configuration";
6+
import {
7+
applyEyeballConfigDefaults,
8+
applyRouterConfigDefaults,
9+
} from "./configuration";
710
import type AssetWorker from "../../asset-worker";
811
import type {
12+
EyeballRouterConfig,
913
JaegerTracing,
1014
RouterConfig,
1115
UnsafePerformanceTimer,
@@ -16,6 +20,7 @@ export interface Env {
1620
ASSET_WORKER: Service<AssetWorker>;
1721
USER_WORKER: Fetcher;
1822
CONFIG: RouterConfig;
23+
EYEBALL_CONFIG: EyeballRouterConfig;
1924

2025
SENTRY_DSN: string;
2126
ENVIRONMENT: Environment;
@@ -55,7 +60,8 @@ export default {
5560
);
5661

5762
const hasStaticRouting = env.CONFIG.static_routing !== undefined;
58-
const config = applyConfigurationDefaults(env.CONFIG);
63+
const config = applyRouterConfigDefaults(env.CONFIG);
64+
const eyeballConfig = applyEyeballConfigDefaults(env.EYEBALL_CONFIG);
5965

6066
const url = new URL(request.url);
6167

packages/workers-shared/router-worker/wrangler.jsonc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"type": "param",
2626
"param": "routerConfig",
2727
},
28+
{
29+
"name": "EYEBALL_CONFIG",
30+
"type": "param",
31+
"param": "eyeballRouterConfig",
32+
"optional": true,
33+
},
2834
{
2935
"name": "ASSET_WORKER",
3036
"type": "internal_assets",

packages/workers-shared/utils/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ export const RouterConfigSchema = z.object({
2020
...InternalConfigSchema.shape,
2121
});
2222

23+
export const EyeballRouterConfigSchema = z.union([
24+
z.object({
25+
limitedAssetsOnly: z.boolean().optional(),
26+
}),
27+
z.null(),
28+
]);
29+
2330
const MetadataStaticRedirectEntry = z.object({
2431
status: z.number(),
2532
to: z.string(),
@@ -79,6 +86,7 @@ export const AssetConfigSchema = z.object({
7986
...InternalConfigSchema.shape,
8087
});
8188

89+
export type EyeballRouterConfig = z.infer<typeof EyeballRouterConfigSchema>;
8290
export type RouterConfig = z.infer<typeof RouterConfigSchema>;
8391
export type AssetConfig = z.infer<typeof AssetConfigSchema>;
8492

0 commit comments

Comments
 (0)