diff --git a/apps/registry/app/api/jobs/[uuid]/route.js b/apps/registry/app/api/jobs/[uuid]/route.js index dfe6add..15894be 100644 --- a/apps/registry/app/api/jobs/[uuid]/route.js +++ b/apps/registry/app/api/jobs/[uuid]/route.js @@ -2,11 +2,22 @@ import { createClient } from '@supabase/supabase-js'; import { NextResponse } from 'next/server'; const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co'; -const supabaseKey = process.env.SUPABASE_KEY; -const supabase = createClient(supabaseUrl, supabaseKey); + +// This ensures the route is always dynamic +export const dynamic = 'force-dynamic'; export async function GET(request, { params }) { + // During build time or when SUPABASE_KEY is not available + if (!process.env.SUPABASE_KEY) { + return NextResponse.json( + { message: 'API not available during build' }, + { status: 503 } + ); + } + try { + const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY); + const { data: job, error } = await supabase .from('jobs') .select('*') @@ -26,7 +37,7 @@ export async function GET(request, { params }) { return NextResponse.json(job); } catch (error) { - console.error('Error fetching job:', error); + console.error('Error:', error); return NextResponse.json( { message: 'Internal server error' }, { status: 500 } diff --git a/apps/registry/app/api/resumes/route.js b/apps/registry/app/api/resumes/route.js index b930e11..2bbc874 100644 --- a/apps/registry/app/api/resumes/route.js +++ b/apps/registry/app/api/resumes/route.js @@ -3,11 +3,21 @@ import { NextResponse } from 'next/server'; import gravatar from 'gravatar'; const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co'; -const supabaseKey = process.env.SUPABASE_KEY; -const supabase = createClient(supabaseUrl, supabaseKey); + +// This ensures the route is always dynamic +export const dynamic = 'force-dynamic'; export async function GET(request) { + // During build time or when SUPABASE_KEY is not available + if (!process.env.SUPABASE_KEY) { + return NextResponse.json( + { message: 'API not available during build' }, + { status: 503 } + ); + } + try { + const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY); const { searchParams } = new URL(request.url); const limit = parseInt(searchParams.get('limit')) || 3000; const page = parseInt(searchParams.get('page')) || 1; @@ -21,50 +31,73 @@ export async function GET(request) { .limit(limit) .range((page - 1) * limit, page * limit - 1); - if (search) { - query.ilike('name', `%${search}%`); + if (search && search.trim() !== '') { + query.textSearch('resume', search.trim(), { + config: 'english', + type: 'websearch', + }); } const { data, error } = await query; - console.timeEnd('getResumes'); if (error) { + console.error('Error fetching resumes:', error); return NextResponse.json( { message: 'Error fetching resumes' }, { status: 500 } ); } + console.timeEnd('getResumes'); + + if (!data) { + return NextResponse.json( + { message: 'No resumes found' }, + { status: 404 } + ); + } + console.time('mapResumes'); const resumes = data.map((row) => { - const resume = JSON.parse(row.resume); - return { - username: row.username, - label: resume?.basics?.label, - image: - resume?.basics?.image || - gravatar.url( - resume?.basics?.email, - { s: '200', r: 'x', d: 'retro' }, - true - ), - name: resume?.basics?.name, - location: resume?.basics?.location, - updated_at: row.updated_at, - created_at: row.created_at, - }; + try { + const resume = JSON.parse(row.resume); + return { + username: row.username, + label: resume?.basics?.label, + image: + resume?.basics?.image || + gravatar.url( + resume?.basics?.email || '', + { + s: '200', + r: 'x', + d: 'retro', + }, + true + ), + name: resume?.basics?.name, + location: resume?.basics?.location, + updated_at: row.updated_at, + created_at: row.created_at, + }; + } catch (e) { + console.error('Error parsing resume:', e); + return { + username: row.username, + label: 'Error parsing resume', + image: gravatar.url('', { s: '200', r: 'x', d: 'retro' }, true), + name: row.username, + location: null, + updated_at: row.updated_at, + created_at: row.created_at, + }; + } }); console.timeEnd('mapResumes'); - console.time('sortResumes'); - resumes.sort((a, b) => { - return new Date(b.created_at) - new Date(a.created_at); - }); - console.timeEnd('sortResumes'); - return NextResponse.json(resumes); } catch (error) { - console.error('Error processing resumes:', error); + console.error('Error:', error); return NextResponse.json( { message: 'Internal server error' }, { status: 500 } diff --git a/apps/registry/app/explore/page.js b/apps/registry/app/explore/page.js index 4b038ae..16dba61 100644 --- a/apps/registry/app/explore/page.js +++ b/apps/registry/app/explore/page.js @@ -3,8 +3,6 @@ import ClientResumes from './ClientResumes'; import gravatar from 'gravatar'; const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co'; -const supabaseKey = process.env.SUPABASE_KEY; -const supabase = createClient(supabaseUrl, supabaseKey); const ITEMS_PER_PAGE = 100; @@ -20,8 +18,18 @@ export const metadata = { }, }; +// This makes the page static at build time +export const dynamic = 'force-dynamic'; + async function getResumes(page = 1, search = '') { try { + // During build time, return empty data + if (!process.env.SUPABASE_KEY) { + return { resumes: [], totalCount: 0, totalPages: 0 }; + } + + const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY); + // First get the total count let countQuery = supabase .from('resumes') diff --git a/apps/registry/app/jobs/page.js b/apps/registry/app/jobs/page.js index a338775..71439ba 100644 --- a/apps/registry/app/jobs/page.js +++ b/apps/registry/app/jobs/page.js @@ -7,29 +7,40 @@ const ClientJobBoard = dynamic(() => import('./ClientJobBoard'), { }); const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co'; -const supabaseKey = process.env.SUPABASE_KEY; -const supabase = createClient(supabaseUrl, supabaseKey); + +// This ensures the page is dynamic at runtime async function getJobs() { - const ninetyDaysAgo = new Date(); - ninetyDaysAgo.setDate(ninetyDaysAgo.getDate() - 90); - - const { data: jobs, error } = await supabase - .from('jobs') - .select('*') - .gte('created_at', ninetyDaysAgo.toISOString()) - .order('created_at', { ascending: false }); - - if (error) { - console.error('Error fetching jobs:', error); - return []; + // During build time or when SUPABASE_KEY is not available + if (!process.env.SUPABASE_KEY) { + return { jobs: [], error: null }; } - return jobs || []; + try { + const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY); + const ninetyDaysAgo = new Date(); + ninetyDaysAgo.setDate(ninetyDaysAgo.getDate() - 90); + + const { data: jobs, error } = await supabase + .from('jobs') + .select('*') + .gte('created_at', ninetyDaysAgo.toISOString()) + .order('created_at', { ascending: false }); + + if (error) { + console.error('Error fetching jobs:', error); + return { jobs: [], error }; + } + + return { jobs: jobs || [], error: null }; + } catch (error) { + console.error('Error:', error); + return { jobs: [], error }; + } } export default async function JobsPage() { - const initialJobs = await getJobs(); + const { jobs } = await getJobs(); return (