ajout du fichier de route

This commit is contained in:
mrtoine 2025-10-01 14:42:59 +02:00
parent c851865728
commit ef1ba911d9
4 changed files with 125 additions and 27 deletions

View file

@ -0,0 +1,26 @@
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 });
}
}

View file

@ -19,9 +19,8 @@ export default function ContactComponent() {
useEffect(() => {
if (!onContactPage) return;
// Essaye avec BACKEND_URL, sinon fallback vers une route locale hypothétique
const backend = (process.env.BACKEND_URL as string) || "http://127.0.0.1:5000/api";
const url = backend ? `${backend}/contact` : "http://127.0.0.1:5000/api/contact";
// Appelle l'API interne Next.js qui proxy vers le BACKEND_URL côté serveur
const url = "/api/contact";
fetch(url, { cache: "no-store" })
.then((res) => (res.ok ? res.json() : Promise.reject(new Error("fetch contact failed"))))

View file

@ -1,5 +1,10 @@
async function getProjects() {
const res = await fetch("http://127.0.0.1:5000/api/projects/", {
const baseUrl = process.env.BACKEND_URL;
if (!baseUrl) {
throw new Error("Variable d'environnement BACKEND_URL manquante");
}
const res = await fetch(`${baseUrl}/projects/`, {
cache: "no-store",
});