Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix build #164

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions apps/registry/app/api/jobs/[uuid]/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('*')
Expand All @@ -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 }
Expand Down
12 changes: 10 additions & 2 deletions apps/registry/app/explore/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,8 +18,18 @@ export const metadata = {
},
};

// This makes the page static at build time
export const dynamic = 'force-dynamic';
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect comment about page behavior

The comment "This makes the page static at build time" contradicts the actual behavior of force-dynamic, which ensures the page is dynamically rendered at runtime. This comment could mislead developers.

-// This makes the page static at build time
+// This ensures the page is dynamically rendered at runtime
export const dynamic = 'force-dynamic';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// This makes the page static at build time
export const dynamic = 'force-dynamic';
// This ensures the page is dynamically rendered at runtime
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')
Expand Down
22 changes: 17 additions & 5 deletions apps/registry/pages/api/jobs/all.js
Original file line number Diff line number Diff line change
@@ -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' });
}
}
Loading