Initial commit
This commit is contained in:
32
qr-web/src/app/api/folders/route.ts
Normal file
32
qr-web/src/app/api/folders/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
const QR_API_URL = process.env.QR_API_URL || 'http://qr_api:8080';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const res = await fetch(`${QR_API_URL}/folders`, { cache: 'no-store' });
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
return Response.json({ error: data?.error ?? 'Failed' }, { status: res.status });
|
||||
}
|
||||
return Response.json(Array.isArray(data) ? data : data);
|
||||
} catch (e) {
|
||||
return Response.json({ error: String(e) }, { status: 502 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const res = await fetch(`${QR_API_URL}/folders`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
return Response.json({ error: data?.error ?? 'Failed' }, { status: res.status });
|
||||
}
|
||||
return Response.json(data);
|
||||
} catch (e) {
|
||||
return Response.json({ error: String(e) }, { status: 502 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user