any way to use the binding with hono without passing the service url?
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.
7 Replies
I believe you should be able to do something like
const res = await c.env.USERS_WORKER.fetch("http://example/");
Yes, but I wanted to know if I should do it without putting the URL, since I have several workers and this would save me from having one more variable.
Sorry should of clarified. I don't believe it just has to be a valid URL so for all your requests it could be
const res = await c.env.USERS_WORKER.fetch("http://example/<path>");
. I don't think you need to worry about it being a valid hostnameI got it and it worked! :O. Will it work the same in production???
It should do.
ty dude!
You can use RPC, so you do not have to use
fetch
and also, you do not have to make it public (no public url).
https://developers.cloudflare.com/workers/runtime-apis/rpc/
https://blog.cloudflare.com/javascript-native-rpc/
https://github.com/cloudflare/js-rpc-and-entrypoints-demo