Environment variables

Hey Im having trouble getting my final build of cloudflare to use my environment variables.

This is my code
export async function onRequest(context) {
    const supabaseConfig = {
      supabaseUrl: context.env.LIVE_SUPABASE_URL,
      supabaseKey: context.env.LIVE_SUPABASE_KEY
    };
  
    return new Response(JSON.stringify(supabaseConfig), {
      headers: {
        'Content-Type': 'application/json'
      }
    });
  }

import { createClient } from '@supabase/supabase-js';

async function initializeSupabase() {
    const response = await fetch('../functions/supabase-config');
    try {
        const { supabaseUrl, supabaseKey } = await response.json();

        if (!response.supabaseUrl || !response.supabaseKey) {
            throw new Error('Supabase configuration is incomplete');
        }

        return createClient(supabaseUrl, supabaseKey);
    } catch (error) {
        const supabaseUrl = process.env.REACT_APP_SUPABASE_URL;
        const supabaseKey = process.env.REACT_APP_SUPABASE_ANON_KEY;

        return createClient(supabaseUrl, supabaseKey);
    }
}

const supabase = await initializeSupabase();

export default supabase;


It skips to the local environment variable even in live production which tells me that the try catch is failing when the environment variable from cloudflare is being queried.

Any ideas?
Was this page helpful?