The best way to control Claude Code, Codex and more from any computer or phone

main
ts 27 lines 1.06 KB
Raw
1 // Async (non-Effect) Worker that exercises the native `flagship` binding:
2 // `/details?flag=<key>&country=<c>` evaluates `env.FLAGS.getBooleanDetails`
3 // with the query's context. Used by the local (dev) test against both the
4 // local simulator and, via `Alchemy.remote()`, the remote-proxied live app.
5 interface Env {
6 FLAGS: {
7 getBooleanDetails(
8 flagKey: string,
9 defaultValue: boolean,
10 context?: Record<string, unknown>,
11 ): Promise<{ value: boolean; variant?: string; reason?: string; errorCode?: string }>;
12 };
13 }
14
15 export default {
16 fetch: async (request: Request, env: Env) => {
17 const url = new URL(request.url);
18 if (url.pathname === "/details") {
19 const flag = url.searchParams.get("flag") ?? "";
20 const context: Record<string, unknown> = { targetingKey: "user-42" };
21 const country = url.searchParams.get("country");
22 if (country !== null) context.country = country;
23 return Response.json(await env.FLAGS.getBooleanDetails(flag, false, context));
24 }
25 return new Response("Not Found", { status: 404 });
26 },
27 };