CleverPatrick
CleverPatrick
CDCloudflare Developers
Created by CleverPatrick on 4/14/2025 in #workers-help
Trying to add a cron job to my worker.
I have an existing worker that uses Hono to expose some API endpoints:
const app = new Hono();
...
export default app;
const app = new Hono();
...
export default app;
I am trying to add a cron job to this worker but I am continuously getting either a "Handler does not export a scheduled() function" error or a, "worker.fetch is not a function" error. I am defining my scheduled.ts worker like this:
export default {

  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
// ...
  },

  async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
  // ...
  }
export default {

  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
// ...
  },

  async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
  // ...
  }
and then updating my main index.ts export like this:
export default {
    app,
    scheduled,
    fetch
}
export default {
    app,
    scheduled,
    fetch
}
But at runtime I am getting the error: Error: Handler does not export a fetch() function.
3 replies
CDCloudflare Developers
Created by CleverPatrick on 3/17/2025 in #workers-help
Multiple workers at the same domain, but multiple paths in wrangler.jsonc
I am trying to setup multiple workers at api.mydomain.com with different paths, but am not sure how to configure the routes section in wrangler.jsonc I want my worker’s APIs to be available at api.mydomain.com/worker. But if I set that in the routes array in wrangler.jsonc like this:
"routes": [
{
"pattern": "api.mydomain.com/worker1/*",
"zone_name": "mydomain.com"
}
]
"routes": [
{
"pattern": "api.mydomain.com/worker1/*",
"zone_name": "mydomain.com"
}
]
It doesn’t work because there is no DNS record set up for api.mydomain.com. If I define a custom domain as part of the routes like this:
"routes": [
{
"pattern": "api.mydomain.com",
"custom_domain": true
},
{
"pattern": "api.mydomain.com/worker1/*",
"zone_name": "mydomain.com"
}
]
"routes": [
{
"pattern": "api.mydomain.com",
"custom_domain": true
},
{
"pattern": "api.mydomain.com/worker1/*",
"zone_name": "mydomain.com"
}
]
My API becomes available at api.mydomain.com, which is not what I want. Also, api.mydomain.com/worker1 routes never work, no matter what variations I try. Can anyone tell me what configuration I need to set to make my API available at a specific path of api.mydomain.com?
3 replies