53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { createClient } from '@supabase/supabase-js';
|
|
import { NextResponse } from 'next/server';
|
|
|
|
export async function GET() {
|
|
try {
|
|
// Get environment variables inside the handler (important for Vercel)
|
|
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
|
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
|
|
|
|
// Validate environment variables
|
|
if (!supabaseUrl) {
|
|
console.error('Missing NEXT_PUBLIC_SUPABASE_URL environment variable');
|
|
return NextResponse.json(
|
|
{ error: 'Server configuration error: Missing Supabase URL' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
if (!supabaseServiceKey) {
|
|
console.error('Missing SUPABASE_SERVICE_ROLE_KEY environment variable');
|
|
return NextResponse.json(
|
|
{ error: 'Server configuration error: Missing Supabase service key' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
const supabase = createClient(supabaseUrl, supabaseServiceKey, {
|
|
auth: {
|
|
autoRefreshToken: false,
|
|
persistSession: false,
|
|
},
|
|
});
|
|
|
|
const { data, error } = await supabase
|
|
.from('mission_control_documents')
|
|
.select('*')
|
|
.order('updated_at', { ascending: false });
|
|
|
|
if (error) {
|
|
console.error('Supabase error:', error);
|
|
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
}
|
|
|
|
return NextResponse.json({ documents: data || [] });
|
|
} catch (err: any) {
|
|
console.error('API error:', err);
|
|
return NextResponse.json(
|
|
{ error: err.message || 'Unknown error occurred' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|