23 lines
691 B
TypeScript
23 lines
691 B
TypeScript
import { apiFetch, jsonResponse } from '../../_lib/api';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export async function GET(req: Request): Promise<Response> {
|
|
const { searchParams } = new URL(req.url);
|
|
const query = searchParams.toString();
|
|
const path = query ? `/routes?${query}` : '/routes';
|
|
const res = await apiFetch(path);
|
|
const body = await res.json();
|
|
return jsonResponse(body, res.status);
|
|
}
|
|
|
|
export async function POST(req: Request): Promise<Response> {
|
|
const body = await req.json();
|
|
const res = await apiFetch('/routes', {
|
|
method: 'POST',
|
|
body: JSON.stringify(body),
|
|
});
|
|
const payload = await res.json();
|
|
return jsonResponse(payload, res.status);
|
|
}
|