Use same-origin /api in the browser so builds are not stuck with baked-in localhost. Server-side fetches use INTERNAL_API_URL, NEXT_PUBLIC_API_URL, or loopback. Centralize logic in lib/api-base.ts. Made-with: Cursor
30 lines
775 B
TypeScript
30 lines
775 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import { apiUrl } from '@/lib/api-base';
|
|
|
|
export async function GET() {
|
|
let upstream: Response;
|
|
try {
|
|
upstream = await fetch(apiUrl('/calendar/ics'), {
|
|
headers: { Accept: 'text/calendar' },
|
|
cache: 'no-store',
|
|
});
|
|
} catch {
|
|
return new NextResponse('Calendar service unavailable', { status: 502 });
|
|
}
|
|
|
|
if (!upstream.ok) {
|
|
return new NextResponse('Failed to fetch calendar', { status: upstream.status });
|
|
}
|
|
|
|
const body = await upstream.text();
|
|
|
|
return new NextResponse(body, {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': 'text/calendar; charset=utf-8',
|
|
'Cache-Control': 'public, max-age=300',
|
|
'Content-Disposition': 'inline; filename="bbe-events.ics"',
|
|
},
|
|
});
|
|
}
|