how to get environment variables within a server route using cloudflare? #1100
-
import { PageServerLoad } from '@analogjs/router';
const env = import.meta.env || process.env;
export const isProduction = env['VITE_PRODUCTION'] === 'true';
export const load = async ({
params, // params/queryParams from the request
req, // H3 Request
res, // H3 Response handler
fetch, // internal fetch for direct API calls
}: PageServerLoad) => {
return { isProduction };
}; the above code works nicely locally but not with wrangler. |
Beta Was this translation helpful? Give feedback.
Answered by
brandonroberts
May 22, 2024
Replies: 1 comment 1 reply
-
Yes, you should be able to get it from the event context export const load = async ({
params, // params/queryParams from the request
req, // H3 Request
res, // H3 Response handler
fetch, // internal fetch for direct API calls,
event, // <---- Full H3 Event
}: PageServerLoad) => {
console.log(event.context['cf'])
return { isProduction };
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
stewones
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, you should be able to get it from the event context