Bugeez
Bugeez
CDCloudflare Developers
Created by Bugeez on 5/16/2024 in #pages-help
Can't import my env in my Function in Astro
Hello, I'm currently working on an Astro project and I'm trying to hide my API key using environment variables or secrets. However, when I attempt to import them into my code after publishing the page, it shows the error message:
"Cannot read properties of undefined (reading 'TEST')".
"Cannot read properties of undefined (reading 'TEST')".
I'm using Cloudflare SSR in a hybrid setup. Here's the code from my function:
export const prerender = false;

export async function GET(request, env, ctx) {
try {
const value = await env.TEST.get("STAGE_API_KEY");

if (value === null) {
return new Response("Value not found", { status: 404 });
}

return new Response(value);
} catch (e) {
return new Response(e.message, { status: 500 });
}
}
export const prerender = false;

export async function GET(request, env, ctx) {
try {
const value = await env.TEST.get("STAGE_API_KEY");

if (value === null) {
return new Response("Value not found", { status: 404 });
}

return new Response(value);
} catch (e) {
return new Response(e.message, { status: 500 });
}
}
If anybody has a solution to this issue, it would really help me out.
10 replies