ENV Variables not found

hello, i am using hono, i have two routes one is list and other is image
import { Hono } from 'hono/quick';
import { createClient } from '@supabase/supabase-js';

type Bindings = {
SUPABASE_URL: string;
SUPABASE_KEY: string;
TOKEN: string;
};

const app = new Hono<{ Bindings: Bindings }>();

// Routes
app.get('/image', async (context) => {
const { env } = context

console.log(env);
if (!env || !env.SUPABASE_URL || !env.SUPABASE_KEY) {
return context.json({ error: true, message: 'Environment not found' }, 500);
}

try {
// ....
} catch (error) {
if (error instanceof Error) {
console.log(error);
return context.json({ error: true, message: error.message }, 500);
}
}
});

app.get('/list', async (context) => {
const { env } = context;
if (!env || !env.SUPABASE_URL || !env.SUPABASE_KEY) {
return context.json({ error: true, message: 'Environment not found' }, 500);
}

const key = context.req.query('key');
if (!key || context.env.TOKEN !== key) {
return context.json({ error: true, message: 'Invalid token' }, 401);
}

try {
// ...
} catch (error) {
if (error instanceof Error) {
console.log(error);
return context.json({ error: true, message: error.message }, 500);
}
}
});

export default app;
import { Hono } from 'hono/quick';
import { createClient } from '@supabase/supabase-js';

type Bindings = {
SUPABASE_URL: string;
SUPABASE_KEY: string;
TOKEN: string;
};

const app = new Hono<{ Bindings: Bindings }>();

// Routes
app.get('/image', async (context) => {
const { env } = context

console.log(env);
if (!env || !env.SUPABASE_URL || !env.SUPABASE_KEY) {
return context.json({ error: true, message: 'Environment not found' }, 500);
}

try {
// ....
} catch (error) {
if (error instanceof Error) {
console.log(error);
return context.json({ error: true, message: error.message }, 500);
}
}
});

app.get('/list', async (context) => {
const { env } = context;
if (!env || !env.SUPABASE_URL || !env.SUPABASE_KEY) {
return context.json({ error: true, message: 'Environment not found' }, 500);
}

const key = context.req.query('key');
if (!key || context.env.TOKEN !== key) {
return context.json({ error: true, message: 'Invalid token' }, 401);
}

try {
// ...
} catch (error) {
if (error instanceof Error) {
console.log(error);
return context.json({ error: true, message: error.message }, 500);
}
}
});

export default app;
when i try to access to the route /list everything works fine a supabase client is intialised and im returned number of files i have but when i go to route image i get the error that Environment not found and when i log the env it seems to be an empty object
1 Reply
Oreki
OrekiOP15mo ago
it suddenly started working when i manually added them in vars and removed supabase NotLikeThis
Want results from more Discord servers?
Add your server