Files
hermes-os/app/api/sessions/[id]/route.ts
T

51 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
const BACKEND = process.env.HERMES_BACKEND_URL || "http://127.0.0.1:8643";
export async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
try {
const res = await fetch(BACKEND + "/api/sessions/" + id);
const data = await res.text();
return new NextResponse(data, {
status: res.status,
headers: { "content-type": "application/json" },
});
} catch {
return NextResponse.json({ error: "backend unreachable" }, { status: 502 });
}
}
export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const body = await req.text();
try {
const res = await fetch(BACKEND + "/api/sessions/" + id, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body,
});
const data = await res.text();
return new NextResponse(data, {
status: res.status,
headers: { "content-type": "application/json" },
});
} catch {
return NextResponse.json({ error: "backend unreachable" }, { status: 502 });
}
}
export async function DELETE(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
try {
const res = await fetch(BACKEND + "/api/sessions/" + id, { method: "DELETE" });
const data = await res.text();
return new NextResponse(data, {
status: res.status,
headers: { "content-type": "application/json" },
});
} catch {
return NextResponse.json({ error: "backend unreachable" }, { status: 502 });
}
}