ivarec
04/25/2023, 1:37 AMminiflare
and the modules syntax, so I'm falling back to service workers. Everything works fine, except that I can't seem to access my service bindings.
Here is my index.js
file as a minimal test case:
js
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest (request) {
const res = dbg.fetch()
return new Response(`Hello from gateway -> ${res}`)
}
And my wrangler.toml
file:
toml
name = "my-worker"
main = "src/index.js"
compatibility_date = "2023-04-24"
services = [
{ binding = "dbg", service = "my-debug-service" }
]
routes = [
{ pattern = "localhost", custom_domain = true }
]
[vars]
foo = "BAR"
I can see the following in my logs:
Your worker has access to the following bindings:
- Services:
- dbg: my-debug-service
- Vars:
- foo: "BAR"
But when I try to access it via wrangler dev
or wrangler dev --local
, I get the following error:
ReferenceError: dbg is not defined
Btw, accessing "foo" works. It's only the service binding that's giving me headaches.
What am I missing?