The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | // Reads/increments the user's Counter Durable Object (exported by |
| 2 | // worker-entry.ts through nitro's entry/exports seam) via the COUNTER |
| 3 | // namespace binding — same-worker JS RPC. |
| 4 | interface CounterStub { |
| 5 | get: () => Promise<number>; |
| 6 | increment: () => Promise<number>; |
| 7 | } |
| 8 | |
| 9 | interface CounterNamespace { |
| 10 | idFromName: (name: string) => unknown; |
| 11 | get: (id: unknown) => CounterStub; |
| 12 | } |
| 13 | |
| 14 | export default defineEventHandler(async (event) => { |
| 15 | const env = (event.context.cloudflare as { env?: Record<string, unknown> } | undefined)?.env; |
| 16 | const namespace = env?.COUNTER as CounterNamespace | undefined; |
| 17 | if (namespace === undefined) { |
| 18 | throw createError({ |
| 19 | statusCode: 500, |
| 20 | statusMessage: "COUNTER binding missing", |
| 21 | }); |
| 22 | } |
| 23 | const stub = namespace.get(namespace.idFromName("fixture")); |
| 24 | const count = event.method === "POST" ? await stub.increment() : await stub.get(); |
| 25 | return { count }; |
| 26 | }); |