mon-site-perso/frontend/app/api/contact/route.ts

26 lines
799 B
TypeScript

import { NextResponse } from "next/server";
export async function GET() {
try {
const baseUrl = process.env.BACKEND_URL;
if (!baseUrl) {
return NextResponse.json({ error: "BACKEND_URL not configured" }, { status: 500 });
}
const url = `${baseUrl.replace(/\/$/, "")}/contact`;
const res = await fetch(url, { cache: "no-store" });
if (!res.ok) {
return NextResponse.json({ error: "Failed to fetch contact data" }, { status: res.status });
}
const data = await res.json();
// Ensure we only expose expected fields
const { email, linkedin, github } = data || {};
return NextResponse.json({ email, linkedin, github }, { status: 200 });
} catch (error) {
return NextResponse.json({ error: "Unexpected error" }, { status: 500 });
}
}