From d626c2a49897cee249090939a2b7745f19b799ff Mon Sep 17 00:00:00 2001 From: Hannah dagemark Date: Fri, 14 Aug 2026 22:37:11 +0200 Subject: [PATCH] Add basic API routing for BFF --- app/api/projects/route.ts | 0 app/api/services/[id]/route.ts | 29 ++++++++++++++++++++++++++++ app/api/services/route.ts | 35 ++++++++++++++++++++++++++++++++++ app/api/users/[id]/route.ts | 0 app/api/users/route.ts | 32 +++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 app/api/projects/route.ts create mode 100644 app/api/services/[id]/route.ts create mode 100644 app/api/services/route.ts create mode 100644 app/api/users/[id]/route.ts create mode 100644 app/api/users/route.ts diff --git a/app/api/projects/route.ts b/app/api/projects/route.ts new file mode 100644 index 0000000..e69de29 diff --git a/app/api/services/[id]/route.ts b/app/api/services/[id]/route.ts new file mode 100644 index 0000000..49402bb --- /dev/null +++ b/app/api/services/[id]/route.ts @@ -0,0 +1,29 @@ +const BACKEND_URL = process.env.BACKEND_URL; + +export async function GET({ params }: { params: Promise<{ id: string }> }) { + const { id } = await params; + const response = await fetch(`${BACKEND_URL}/services/${id}`); + + if (!response.ok) { + return new Response("Request failed in backend", { + status: response.status, + }); + } + + const data = await response.json(); + + return Response.json(data); +} + +export async function DELETE({ params }: { params: Promise<{ id: string }> }) { + const { id } = await params; + const response = await fetch(`${BACKEND_URL}/services/${id}`, { + method: "DELETE", + }); + + const data = await response.json(); + + return Response.json(data, { + status: response.status, + }); +} diff --git a/app/api/services/route.ts b/app/api/services/route.ts new file mode 100644 index 0000000..7c2920f --- /dev/null +++ b/app/api/services/route.ts @@ -0,0 +1,35 @@ +const BACKEND_URL = process.env.BACKEND_URL; + +export async function GET() { + console.log("Made it to the GET SERVICES ROUTE!"); + + const response = await fetch(`${BACKEND_URL}/services/all`); + + if (!response.ok) { + return new Response("Request failed in backend", { + status: response.status, + }); + } + + const data = await response.json(); + + return Response.json(data); +} + +export async function POST(request: Request) { + const body = await request.json(); + + const response = await fetch(`${BACKEND_URL}/services`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + }); + + const data = await response.json(); + + return Response.json(data, { + status: response.status, + }); +} diff --git a/app/api/users/[id]/route.ts b/app/api/users/[id]/route.ts new file mode 100644 index 0000000..e69de29 diff --git a/app/api/users/route.ts b/app/api/users/route.ts new file mode 100644 index 0000000..15eaa43 --- /dev/null +++ b/app/api/users/route.ts @@ -0,0 +1,32 @@ +const BACKEND_URL = process.env.BACKEND_URL; + +export async function GET() { + const response = await fetch(`${BACKEND_URL}/users`); + + if (!response.ok) { + return new Response("Request failed in backend", { status: response.status, }); + } + + const data = await response.json(); + + return Response.json(data); +} + +export async function POST(request: Request) { + + const body = await request.json(); + + const response = await fetch(`${BACKEND_URL}/users`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + }); + + const data = await response.json(); + + return Response.json(data, { + status: response.status, + }); +} \ No newline at end of file