diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/pages/api/counter.ts | 8 | ||||
| -rw-r--r-- | src/worker.ts | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/pages/api/counter.ts b/src/pages/api/counter.ts index 152dc54..1d3d0b7 100644 --- a/src/pages/api/counter.ts +++ b/src/pages/api/counter.ts @@ -4,8 +4,8 @@ interface Env { COUNTER_DO: DurableObjectNamespace; } -export const GET: APIRoute = async ({ request }) => { - const env = request.cf?.env as Env; +export const GET: APIRoute = async ({ locals }) => { + const env = locals.runtime.env as Env; if (!env?.COUNTER_DO) { return new Response(JSON.stringify({ error: 'Durable Object not available' }), { status: 500, @@ -24,8 +24,8 @@ export const GET: APIRoute = async ({ request }) => { }); }; -export const POST: APIRoute = async ({ request }) => { - const env = request.cf?.env as Env; +export const POST: APIRoute = async ({ request, locals }) => { + const env = locals.runtime.env as Env; if (!env?.COUNTER_DO) { return new Response(JSON.stringify({ error: 'Durable Object not available' }), { status: 500, diff --git a/src/worker.ts b/src/worker.ts index 0ad83a6..5eb9d5d 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -20,8 +20,8 @@ class CounterDurableObject extends DurableObject<Env> { const currentValue = (await this.ctx.storage.get<number>('counter')) || 0; const newValue = currentValue + 1; await this.ctx.storage.put('counter', newValue); - - return new Response(JSON.stringify({ + + return new Response(JSON.stringify({ counter: newValue, timestamp: new Date().toISOString() }), { @@ -31,7 +31,7 @@ class CounterDurableObject extends DurableObject<Env> { if (pathname === '/get') { const currentValue = (await this.ctx.storage.get<number>('counter')) || 0; - return new Response(JSON.stringify({ + return new Response(JSON.stringify({ counter: currentValue, timestamp: new Date().toISOString() }), { @@ -41,7 +41,7 @@ class CounterDurableObject extends DurableObject<Env> { if (pathname === '/reset') { await this.ctx.storage.put('counter', 0); - return new Response(JSON.stringify({ + return new Response(JSON.stringify({ counter: 0, message: 'Counter reset', timestamp: new Date().toISOString() |
