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.
This commit is contained in:
xixu-me committed 2025-07-29 15:16:38 +08:00
1 parent d906756141
commit a31ff1f0c2
1 file changed
+13 -11
+13 -11
View File
@@ -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> {
): void {
ctx.waitUntil(handleScheduled(event, env));
}
@@ -61,6 +52,17 @@ async function handleScheduled(event: ScheduledEvent, env: Env): Promise<void> {
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