From 40e23937c96a11b79be6cbd5f5636993490a0924 Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Tue, 29 Jul 2025 15:16:38 +0800 Subject: [PATCH] Refactor worker export configuration Moved the worker export configuration to the end of the file and refactored the scheduled handler to be a synchronous function. This improves code organization and clarity. --- src/index.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 14348a8..d7d984d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,15 +26,6 @@ import { createStandardResponse } from "./lib/types"; */ const app = new Hono<{ Bindings: Env }>(); -/** - * Worker export configuration - * Defines the main fetch handler and scheduled event handler - */ -export default { - fetch: app.fetch, - scheduled, -}; - /** * Scheduled event handler for periodic maintenance tasks * Executes every 5 minutes as configured in wrangler.jsonc @@ -42,11 +33,11 @@ export default { * @param env Environment bindings * @param ctx Execution context for background tasks */ -async function scheduled( +function scheduled( event: ScheduledEvent, env: Env, ctx: ExecutionContext -): Promise { +): void { ctx.waitUntil(handleScheduled(event, env)); } @@ -61,6 +52,17 @@ async function handleScheduled(event: ScheduledEvent, env: Env): Promise { clearMemoryCache(); } +/** + * Worker export configuration + * Defines the main fetch handler and scheduled event handler + */ +const worker = { + fetch: app.fetch, + scheduled, +}; + +export default worker; + /** * API Route Definitions * Defines all available endpoints and their handlers