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:
1 parent
d906756141
commit
a31ff1f0c2
1 file changed
+13
-11
+13
-11
@@ -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
|
||||
|
||||
Reference in new issue
Block a user