feat(web): add groups page with RouteManager and route handler proxies
Implements the Groups & Routes admin page with a client-side RouteManager component (add/delete sync routes via fetch), server-side groups page that pre-fetches groups/routes from the API, and Next.js Route Handler proxies for /api/routes (GET, POST) and /api/routes/[id] (DELETE). Adds a custom jest environment that polyfills Node 18+ native fetch into the jsdom sandbox so tests can use jest.spyOn(global, 'fetch'). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
const API_URL = process.env.API_URL ?? 'http://localhost:3001';
|
||||
|
||||
export async function DELETE(
|
||||
_req: Request,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
const res = await fetch(`${API_URL}/routes/${id}`, { method: 'DELETE' });
|
||||
return new Response(null, { status: res.status });
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
const API_URL = process.env.API_URL ?? 'http://localhost:3001';
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const url = new URL(`${API_URL}/routes`);
|
||||
searchParams.forEach((v, k) => url.searchParams.set(k, v));
|
||||
const res = await fetch(url, { cache: 'no-store' });
|
||||
return Response.json(await res.json(), { status: res.status });
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const body = await req.json();
|
||||
const res = await fetch(`${API_URL}/routes`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
return Response.json(await res.json(), { status: res.status });
|
||||
}
|
||||
Reference in New Issue
Block a user