Add basic API routing for BFF
This commit is contained in:
parent
545d70abc3
commit
d626c2a498
5 changed files with 96 additions and 0 deletions
0
app/api/projects/route.ts
Normal file
0
app/api/projects/route.ts
Normal file
29
app/api/services/[id]/route.ts
Normal file
29
app/api/services/[id]/route.ts
Normal file
|
|
@ -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,
|
||||||
|
});
|
||||||
|
}
|
||||||
35
app/api/services/route.ts
Normal file
35
app/api/services/route.ts
Normal file
|
|
@ -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,
|
||||||
|
});
|
||||||
|
}
|
||||||
0
app/api/users/[id]/route.ts
Normal file
0
app/api/users/[id]/route.ts
Normal file
32
app/api/users/route.ts
Normal file
32
app/api/users/route.ts
Normal file
|
|
@ -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,
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue