For Workes & Pages, what is the name of the domain?
workers
What is the error message?
✘ [ERROR] TypeError: Invalid URL: /
What is the issue or error you’re encountering
i want to use hono with service bindings
What steps have you taken to resolve the issue?
I am using several workers and I would like to use one as a gateway and communicate with all of them through service bindings, but is there a way to use the service binding without passing the full URL of the other service? I attach the example
i get this error
✘ [ERROR] TypeError: Invalid URL: /
only works if i set the url like this
const res = await c.env.USERS_WORKER.fetch(“http://localhost:8787/”);
But since I have several workers, I’d need to define many variables and I’d like to know if there’s a way to save myself that step.
You can call a service binding with RPC, which lets you define methods in the target worker that you can call from another worker directly. See the documentation here.
More simply, when you call a service binding via fetch, the URL doesn’t actually mean anything. It does get passed to the target worker in request.url, but if you’re not checking that in the target worker, it can be any URL. You can just put https://foo and it will work, because the actual target of the call is defined by the service binding.
Yes, law about rpc but I didn’t find a way to make it work with hono, I am using several workers with hono and I would like to bind them with RPC but I couldn’t find an example either, that is, how do I define my method in my worker A with workerEntryPoint and how do I consume it in Worker B, do you have any by chance? thanks for responding
I can’t think of any reason Hono would make a difference; it should work the same way.
But if you want it to be easy, you can just use fetch with a dummy URL. The URL need not be correct and this doesn’t require adding or changing any code in your target Worker. The only reason it was giving you an error was because you didn’t include the https:// part.