diff options
| author | Yuval Adam <_@yuv.al> | 2025-07-10 14:08:31 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2025-07-10 14:08:31 +0200 |
| commit | 156afc6ba5e9ab406ef167aa318baea18e60b51c (patch) | |
| tree | 515090557e75124af933a3e9926d41967718c189 /src/pages | |
| parent | a80d4a20bee44996171db2916fad900385fa7263 (diff) | |
Diffstat (limited to 'src/pages')
| -rw-r--r-- | src/pages/api/counter.ts | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/pages/api/counter.ts b/src/pages/api/counter.ts index 4f42236..d6d3134 100644 --- a/src/pages/api/counter.ts +++ b/src/pages/api/counter.ts @@ -1,11 +1,9 @@ import type { APIRoute } from 'astro'; -interface Env { - COUNTER_DO: DurableObjectNamespace; -} +const getEnv = (locals: any) => (locals as any).runtime.env as Env; export const GET: APIRoute = async ({ locals }) => { - const env = locals.runtime.env as Env; + const env = getEnv(locals); const id = env.COUNTER_DO.idFromName('counter'); const stub = env.COUNTER_DO.get(id); const response = await stub.fetch('https://counter.do/get'); @@ -13,7 +11,7 @@ export const GET: APIRoute = async ({ locals }) => { }; export const POST: APIRoute = async ({ locals }) => { - const env = locals.runtime.env as Env; + const env = getEnv(locals); const id = env.COUNTER_DO.idFromName('counter'); const stub = env.COUNTER_DO.get(id); const response = await stub.fetch('https://counter.do/increment'); |
