From 68ff6f90b773d688a6a908584fc93806e5212a95 Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Wed, 20 Nov 2024 01:15:02 +1100 Subject: [PATCH 1/4] fix build --- apps/registry/app/explore/page.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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') From 52f814f9c41f28269f11facef74eca2faa8bc28d Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Wed, 20 Nov 2024 01:19:54 +1100 Subject: [PATCH 2/4] fix build --- apps/registry/app/api/jobs/[uuid]/route.js | 17 ++++++++++++++--- apps/registry/pages/api/jobs/all.js | 22 +++++++++++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) 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/pages/api/jobs/all.js b/apps/registry/pages/api/jobs/all.js index 76d4274..7ee9931 100644 --- a/apps/registry/pages/api/jobs/all.js +++ b/apps/registry/pages/api/jobs/all.js @@ -1,27 +1,39 @@ const { createClient } = require('@supabase/supabase-js'); const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co'; -const supabaseKey = process.env.SUPABASE_KEY; -const supabase = createClient(supabaseUrl, supabaseKey); + +export const config = { + runtime: 'edge', +}; export default async function handler(req, res) { if (req.method !== 'GET') { return res.status(405).json({ message: 'Method not allowed' }); } + // During build time or when SUPABASE_KEY is not available + if (!process.env.SUPABASE_KEY) { + return res.status(503).json({ message: 'API not available during build' }); + } + try { + const supabase = createClient(supabaseUrl, process.env.SUPABASE_KEY); + // Get all jobs from the last 90 days, sorted by creation date descending const { data: jobs, error } = await supabase .from('jobs') .select('*') - .gte('created_at', new Date(Date.now() - 60 * 24 * 60 * 90 * 1000).toISOString()) + .gte( + 'created_at', + new Date(Date.now() - 60 * 24 * 60 * 90 * 1000).toISOString() + ) .order('created_at', { ascending: false }); if (error) throw error; - return res.status(200).json(jobs); + return res.status(200).json(jobs || []); } catch (error) { console.error('Error fetching jobs:', error); - return res.status(500).json({ message: 'Error fetching jobs', error: error.message }); + return res.status(500).json({ message: 'Internal server error' }); } } From a3cd5f077d4ab7364a5b0908cd6bea259b37b69b Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Wed, 20 Nov 2024 01:24:29 +1100 Subject: [PATCH 3/4] fix build --- apps/registry/app/api/resumes/route.js | 89 ++++++++++++++++++-------- 1 file changed, 61 insertions(+), 28 deletions(-) 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 } From 3483a9852eb8fa3bf108e8af16fd0eb65bb07d79 Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Wed, 20 Nov 2024 01:30:29 +1100 Subject: [PATCH 4/4] fix build --- apps/registry/app/jobs/page.js | 45 +++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 17 deletions(-) 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 (
@@ -42,7 +53,7 @@ export default async function JobsPage() {
} > - +