Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 10m3s
Added rate limiting to APIs, cleaned up docs, implemented fallback logic for reviews without text, and added comprehensive n8n guide.
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getHobbies } from '@/lib/directus';
|
|
import { checkRateLimit, getClientIp } from '@/lib/auth';
|
|
|
|
export const runtime = 'nodejs';
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
/**
|
|
* GET /api/hobbies
|
|
*
|
|
* Loads Hobbies from Directus with fallback to static data
|
|
*
|
|
* Query params:
|
|
* - locale: en or de (default: en)
|
|
*/
|
|
export async function GET(request: NextRequest) {
|
|
// Rate Limit: 60 requests per minute
|
|
const ip = getClientIp(request);
|
|
if (!checkRateLimit(ip, 60, 60000)) {
|
|
return NextResponse.json({ error: 'Rate limit exceeded' }, { status: 429 });
|
|
}
|
|
|
|
try {
|
|
const { searchParams } = new URL(request.url);
|
|
const locale = searchParams.get('locale') || 'en';
|
|
|
|
// Try to load from Directus
|
|
const hobbies = await getHobbies(locale);
|
|
|
|
if (hobbies && hobbies.length > 0) {
|
|
return NextResponse.json({
|
|
hobbies,
|
|
source: 'directus'
|
|
});
|
|
}
|
|
|
|
// Fallback: return empty (component will use hardcoded fallback)
|
|
return NextResponse.json({
|
|
hobbies: null,
|
|
source: 'fallback'
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('Error loading hobbies:', error);
|
|
return NextResponse.json(
|
|
{
|
|
hobbies: null,
|
|
error: 'Failed to load hobbies',
|
|
source: 'error'
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|