KV always returning null when proxied

#1

I’m migrating an old service to a new domain, redirecting GET requests with a location header and proxying non-GET requests with fetch, but it seems like kv entries are inaccesible when proxying through the old domain.

This seems to only happen on production. The same requests in the editor works fine.

What can I do to make this work?

#2

First post the code, that would be extremely helpful…

#3

Make sure you use await when getting or putting KV values or you’ll get very unexpected result.

#4

I don’t think my code is relevant in this case. The fact of the matter is that I’m reading kv values:

async function handleRequest(): Promise<Response> {
    return new Response(`value: ${ await kv.get('some_key') }`);
}

addEventListener('fetch', (event) => event.respondWith(handleRequest()));

which properly returns a value from my new domain:

> curl https://new.domain/
value: some_value

and using a simple proxy:

async function handleRequest(): Promise<Response> {
    return fetch('https://new.domain/');
}

addEventListener('fetch', (event) => event.respondWith(handleRequest()));

from my new domain yields no value:

> curl https://old.domain/
value: null

My code is way too long to be able to be posted on a forum in a sightly way.

#5

This is a bug in our implementation – thank you for the report! We’re working on a fix.

Edit: we expect the fix to go live in the middle of next week, around May 1st.

Harris

5 Likes