I have my pages application and a separate worker.
I would like to use a service binding to call this worker from my pages function(s).
I’m able to select the service binding from the function.
However, when I look at the service I am binding to’s triggers, it does not pick up the function.
Calling the binding results in a fetch error.
I have tried:
-Recreating the worker
-Recreating the pages project
- Removing/Adding the binding
- Using a different env var name for the binding.
We know this doesn’t show in the Workers UI today, it does still function though. As long as it’s in the Pages UI, you’re ok.
Are you having any actual problems running it?
It does not actually allow the call, error logs:
"TypeError: Fetch API cannot load: /hello"
await context.env.NOCAPP_API.fetch(new Request('/hello')).then(res => res.text())
I know the binding variable is correct because if I change it to something “incorrect” NOCAPP_API is undefined.
fetch (along with
Request) doesn’t accept paths, you need to provide a hostname (since it won’t be used with service bindings, you can provide anything as long as it’s valid)
Haha oh my goodness…
I spent so much time on this. I can’t believe it’s that simple.
Ok - good to know. thank you will give this a try.
Would really be worth mentioning this in the docs!
There is just this example:
const authResponse = await env.auth.fetch(request.clone());
Which doesn’t illustrate that a hostname is required.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.