Worker talking to worker service with itty-router

I'm trying to get worker-a to talk to worker-b service, the worker-b service is deployed and I'm serving up the worker-a via wrangler dev From worker-a:
...
router.get('/apps', async(request, env) => {
return await env.API.fetch(request.clone())
})
...
router.get('/apps', async(request, env) => {
return await env.API.fetch(request.clone())
})
From worker-b service:
router.get('/apps', async(request, env) => {
return new Response('Hello')
})
router.get('/apps', async(request, env) => {
return new Response('Hello')
})
But I just get
internal error {
stack: Error: internal error,
message: internal error
}
internal error {
stack: Error: internal error,
message: internal error
}
Is there a way to point to my local served worker service to debug what's going wrong?
5 Replies
muslax
muslax2y ago
Workers-b should have wrangler.toml that register workers-a as a service.
honzabit
honzabit2y ago
maybe this could help you (https://developers.cloudflare.com/workers/wrangler/api/#multi-worker-example), you can spawn unstable_dev with unstable_dev('script_path', { logLevel: "debug" } and get debug logs
moonage.dev
moonage.devOP2y ago
it does, and have double checked
muslax
muslax2y ago
You can check in terminal if the request from b reach a
moonage.dev
moonage.devOP2y ago
So even if I tail worker-b and dumb it down to just:
export default {
fetch() {
return new Response('Hello)
}
}
export default {
fetch() {
return new Response('Hello)
}
}
If I hit worker-b, everything works normally and tailing it gives results When I call worker-b from worker-a, also dumbed worker-a down to: index.ts
export default {
fetch(request: Request, env: Env) {
return await env.API.fetch(request.clone())
}
}
export default {
fetch(request: Request, env: Env) {
return await env.API.fetch(request.clone())
}
}
types.ts
export interface Env {
API: Fetcher
}
export interface Env {
API: Fetcher
}
wrangler.toml
...
services = [
{ binding = "API", service = "the-correct-service" }
]
...
services = [
{ binding = "API", service = "the-correct-service" }
]
I just get Error 1101 and tail on worker-b gives no output is it because the request is coming from another worker on the same account? If so, how can I get around it to pass data to worker-b and think service bindings would not run into this issue nvm its working when deployed, just not when local going to mark as resolved but would be nice to know which cmd to use for local to work with service bingings
Want results from more Discord servers?
Add your server