29 lines
863 B
TypeScript
29 lines
863 B
TypeScript
const QR_API_URL = process.env.QR_API_URL || 'http://qr_api:8080';
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const body = await request.json();
|
|
const res = await fetch(`${QR_API_URL}/shorten`, {
|
|
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 ?? 'Shorten failed' },
|
|
{ status: res.status },
|
|
);
|
|
}
|
|
return Response.json(data);
|
|
} catch (e) {
|
|
return Response.json(
|
|
{
|
|
error: 'QR API unreachable',
|
|
detail: e instanceof Error ? e.message : String(e),
|
|
},
|
|
{ status: 502 },
|
|
);
|
|
}
|
|
}
|