#Worker talking to worker service with itty-router

10 messages · Page 1 of 1 (latest)

tidal moon
#

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())
})

From worker-b service:

router.get('/apps', async(request, env) => {
  return new Response('Hello')
})

But I just get

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?

small arrow
#

Workers-b should have wrangler.toml that register workers-a as a service.

thin pasture
tidal moon
small arrow
#

You can check in terminal if the request from b reach a

tidal moon
#

So even if I tail worker-b and dumb it down to just:

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())
  }
}

types.ts

export interface Env {
  API: Fetcher
}

wrangler.toml

...
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