Replace catch-all proxy with dedicated routes, add 404 page
- Dedicated proxy routes for sessions, messages, search, memory, config - Removes [...path] catch-all that conflicted with specific routes - Session detail + delete proxy - Custom 404 page matching design system
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
const BACKEND = process.env.HERMES_BACKEND_URL || "http://127.0.0.1:8643";
|
||||
|
||||
async function proxy(method: string, req: NextRequest) {
|
||||
const qs = req.nextUrl.search;
|
||||
const body = method !== "GET" ? await req.text() : undefined;
|
||||
try {
|
||||
const res = await fetch(BACKEND + "/api/memory" + qs, {
|
||||
method,
|
||||
headers: body ? { "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 GET(req: NextRequest) { return proxy("GET", req); }
|
||||
export async function POST(req: NextRequest) { return proxy("POST", req); }
|
||||
export async function PATCH(req: NextRequest) { return proxy("PATCH", req); }
|
||||
export async function DELETE(req: NextRequest) { return proxy("DELETE", req); }
|
||||
Reference in New Issue
Block a user