good forst commit
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
const API_URL = process.env.API_URL ?? 'http://localhost:3001';
|
||||
import { apiFetch, jsonResponse } from '../../_lib/api';
|
||||
|
||||
export async function GET(req: Request) {
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET(req: Request): Promise<Response> {
|
||||
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 });
|
||||
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) {
|
||||
export async function POST(req: Request): Promise<Response> {
|
||||
const body = await req.json();
|
||||
const res = await fetch(`${API_URL}/routes`, {
|
||||
const res = await apiFetch('/routes', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
return Response.json(await res.json(), { status: res.status });
|
||||
const payload = await res.json();
|
||||
return jsonResponse(payload, res.status);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user