Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KV fails on prerendering #386

Open
TunaYagci opened this issue Dec 1, 2024 · 2 comments
Open

KV fails on prerendering #386

TunaYagci opened this issue Dec 1, 2024 · 2 comments

Comments

@TunaYagci
Copy link

Describe the bug

When I deploy my code to cloudflare using hub's deploy command, api always returns an empty response. 👇

export default eventHandler(async () => {
    return (await hubKV().get('example'))
});

whereas if I skip it during prerendering, it succeeds 👍

export default eventHandler(async () => {
    // Skip during prerendering
    if (import.meta.prerender) return
    return (await hubKV().get('example'))
});

In KV examples and documentation this solution is not observed at all. Am I doing anything wrong? I need KV to be available during prerendering as well.

@atinux
Copy link
Contributor

atinux commented Dec 2, 2024

It is expected as actually when you build & pre-render, most of the time it is within a CI which has a fresh new directory, meaning that the KV store will be empty.

What data do you expect to read from?

@TunaYagci
Copy link
Author

What data do you expect to read from?

I'm expecting to read up to date data, which could also be retrieved by a database but i decided to use KV for performance benefits. Would I have this issue with cloudflare's database as well?

It is expected as actually when you build & pre-render, most of the time it is within a CI which has a fresh new directory, meaning that the KV store will be empty.

Is there any way to defeat this? Should I switch to Cloudflare's rest api? In that case I couldn't understand how I can retrieve the secrets during prerendering. I only found this documentation here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants