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:
@@ -1,63 +0,0 @@
|
||||
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<{ path: string[] }> }) {
|
||||
const { path } = await params;
|
||||
const target = path.join("/");
|
||||
const qs = req.nextUrl.search;
|
||||
const res = await fetch(`${BACKEND}/api/${target}${qs}`);
|
||||
const data = await res.text();
|
||||
return new NextResponse(data, {
|
||||
status: res.status,
|
||||
headers: { "content-type": res.headers.get("content-type") || "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
|
||||
const { path } = await params;
|
||||
const target = path.join("/");
|
||||
const body = await req.text();
|
||||
const res = await fetch(`${BACKEND}/api/${target}`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body,
|
||||
});
|
||||
const data = await res.text();
|
||||
return new NextResponse(data, {
|
||||
status: res.status,
|
||||
headers: { "content-type": res.headers.get("content-type") || "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
export async function PATCH(req: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
|
||||
const { path } = await params;
|
||||
const target = path.join("/");
|
||||
const body = await req.text();
|
||||
const res = await fetch(`${BACKEND}/api/${target}`, {
|
||||
method: "PATCH",
|
||||
headers: { "content-type": "application/json" },
|
||||
body,
|
||||
});
|
||||
const data = await res.text();
|
||||
return new NextResponse(data, {
|
||||
status: res.status,
|
||||
headers: { "content-type": res.headers.get("content-type") || "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
|
||||
const { path } = await params;
|
||||
const target = path.join("/");
|
||||
const body = await req.text();
|
||||
const res = await fetch(`${BACKEND}/api/${target}`, {
|
||||
method: "DELETE",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: body || undefined,
|
||||
});
|
||||
const data = await res.text();
|
||||
return new NextResponse(data, {
|
||||
status: res.status,
|
||||
headers: { "content-type": res.headers.get("content-type") || "application/json" },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
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) {
|
||||
const qs = req.nextUrl.search;
|
||||
try {
|
||||
const res = await fetch(BACKEND + "/api/config" + qs);
|
||||
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 });
|
||||
}
|
||||
}
|
||||
@@ -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); }
|
||||
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
const qs = req.nextUrl.search;
|
||||
try {
|
||||
const res = await fetch(BACKEND + "/api/sessions/" + id + "/messages" + qs);
|
||||
const data = await res.text();
|
||||
return new NextResponse(data, {
|
||||
status: res.status,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
} catch {
|
||||
return NextResponse.json({ items: [], total: 0 }, { status: 502 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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 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 });
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,20 @@ 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) {
|
||||
const qs = req.nextUrl.search;
|
||||
try {
|
||||
const res = await fetch(BACKEND + "/api/sessions" + qs);
|
||||
const data = await res.text();
|
||||
return new NextResponse(data, {
|
||||
status: res.status,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
} catch {
|
||||
return NextResponse.json({ items: [], total: 0 }, { status: 502 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.text();
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
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) {
|
||||
const qs = req.nextUrl.search;
|
||||
try {
|
||||
const res = await fetch(BACKEND + "/api/sessions/search" + qs);
|
||||
const data = await res.text();
|
||||
return new NextResponse(data, {
|
||||
status: res.status,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
} catch {
|
||||
return NextResponse.json({ query: "", count: 0, results: [] }, { status: 502 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import Link from "next/link";
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-20 space-y-4">
|
||||
<div className="text-6xl font-bold" style={{ color: "var(--text-3)" }}>404</div>
|
||||
<p className="text-sm" style={{ color: "var(--text-2)" }}>Page not found</p>
|
||||
<Link
|
||||
href="/"
|
||||
className="px-4 py-2 rounded-xl text-sm font-medium"
|
||||
style={{ background: "var(--accent-dim)", color: "var(--accent)" }}
|
||||
>
|
||||
Back to Pulse
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user