v2
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getSettings } from '@/lib/settings';
|
||||
import { logApiRequest } from '@/lib/api-logger';
|
||||
|
||||
const REVALIDATE = 300; // 5 minutes
|
||||
|
||||
export async function GET() {
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
const settings = await getSettings();
|
||||
const apiKey = settings.apiKey || process.env.API_FOOTBALL_API_KEY;
|
||||
|
||||
if (!apiKey) {
|
||||
return NextResponse.json(
|
||||
{ error: 'API key not configured' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`https://v3.football.api-sports.io/standings?league=${settings.leagueId}&season=${settings.season}`,
|
||||
{
|
||||
headers: {
|
||||
'x-rapidapi-key': apiKey,
|
||||
'x-rapidapi-host': 'v3.football.api-sports.io',
|
||||
},
|
||||
next: { revalidate: REVALIDATE },
|
||||
}
|
||||
);
|
||||
|
||||
const data = await response.json();
|
||||
const duration = Date.now() - startTime;
|
||||
|
||||
logApiRequest('/standings', response.status, duration);
|
||||
|
||||
return NextResponse.json(data, {
|
||||
headers: {
|
||||
'Cache-Control': `public, s-maxage=${REVALIDATE}, stale-while-revalidate=${REVALIDATE * 2}`,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
const duration = Date.now() - startTime;
|
||||
logApiRequest('/standings', 500, duration);
|
||||
console.error('Standings API error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch standings' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user