summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2025-07-10 14:08:31 +0200
committerYuval Adam <_@yuv.al>2025-07-10 14:08:31 +0200
commit156afc6ba5e9ab406ef167aa318baea18e60b51c (patch)
tree515090557e75124af933a3e9926d41967718c189 /src
parenta80d4a20bee44996171db2916fad900385fa7263 (diff)
Cleanup type errorsHEADmain
Diffstat (limited to 'src')
-rw-r--r--src/pages/api/counter.ts8
-rw-r--r--src/worker.ts6
2 files changed, 4 insertions, 10 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');
diff --git a/src/worker.ts b/src/worker.ts
index 52e9f5e..5490e2a 100644
--- a/src/worker.ts
+++ b/src/worker.ts
@@ -3,10 +3,6 @@ import { App } from 'astro/app';
import { handle } from '@astrojs/cloudflare/handler';
import { DurableObject } from 'cloudflare:workers';
-interface Env {
- COUNTER_DO: DurableObjectNamespace;
-}
-
class CounterDurableObject extends DurableObject<Env> {
async fetch(request: Request): Promise<Response> {
const url = new URL(request.url);
@@ -32,7 +28,7 @@ export function createExports(manifest: SSRManifest) {
return {
default: {
async fetch(request, env, ctx) {
- return handle(manifest, app, request, env, ctx);
+ return handle(manifest, app, request as any, env as any, ctx);
}
} satisfies ExportedHandler<Env>,
CounterDurableObject: CounterDurableObject,