Cannot get bindings from KV to worker to operate (Cloudflare)

139 views Asked by At

Running a a script that pull a test page and injects some hreflang links into the header.

For the life of me I can't get the binding to work to the KVs that hold the links to be added.

I added the KV to the Variables in Settings.

enter image description here

edit: I have tried more setting styles like this one enter image description here

and called env.KVStuff but still there is no connection. Still getting no connection errors TypeError: Cannot read properties of undefined (reading 'KVStuff')

Even just putting all the KV code in one place doesn't work

 addEventListener("fetch", (event,env, ctx) => {
    console.log("Got event");
  var getData = () =>  env.NAMESPACE;
   let data =  getData().get("1home");
   console.log("getData",  data);
    event.respondWith(handleRequest(event.request));
  });

I get worker.js:233 TypeError: Cannot read properties of undefined (reading 'NAMESPACE')

I'm getting pretty desperate here.

1

There are 1 answers

1
netchicken On

Solved!

Just take the env off the namespace code and it works