Entegrasyon rehberleri
DRAEVA / Public API
Next.js server proxy rehberi
API anahtarını Client Component'e vermeyin. Route Handler veya güvenilir server katmanı kullanın.
API anahtarını Client Component'e vermeyin. Route Handler veya güvenilir server katmanı kullanın.
Environment
DRAEVA_API_KEY=admin_panel_value
NEXT_PUBLIC_ öneki kullanmayın.
Binary proxy iskeleti
// app/api/background-removal/route.ts
export const runtime = "nodejs";
export async function POST(request: Request): Promise<Response> {
const key = process.env.DRAEVA_API_KEY;
if (!key) return Response.json({ error: "not_configured" }, { status: 503 });
const incoming = await request.formData();
const image = incoming.get("image");
if (!(image instanceof File)) {
return Response.json({ error: "missing_file" }, { status: 400 });
}
const upstream = new FormData();
upstream.set("image", image, image.name);
const response = await fetch(
"https://api.getdraeva.com/bg/v1/background-removals",
{
method: "POST",
headers: { Authorization: `Bearer ${key}` },
body: upstream,
cache: "no-store",
signal: AbortSignal.timeout(45_000),
},
);
const requestId = response.headers.get("x-request-id");
if (!response.ok) {
// Parse application/problem+json and map `type` to your public error contract.
return Response.json(
{ error: "processing_failed", requestId },
{ status: response.status === 429 ? 429 : 503 },
);
}
if (!response.headers.get("content-type")?.startsWith("image/png")) {
return Response.json({ error: "invalid_upstream_response", requestId }, { status: 503 });
}
return new Response(await response.arrayBuffer(), {
headers: {
"Content-Type": "image/png",
"Cache-Control": "no-store",
...(requestId ? { "X-Request-Id": requestId } : {}),
},
});
}
Production ekleri
Bu iskeleti canlıya almadan önce:
- Request body'yi stream sırasında ve parse sonrasında sınırlandırın.
- Magic-byte doğrulaması yapın.
Retry-Afterheader'ını koruyun.- Upstream
typeslug'larını kendi güvenli hata sözleşmenize eşleyin. - API
detailmetnini doğrudan kullanıcıya göstermeyin. - API anahtarı/header, görsel byte'ları ve kullanıcı profilini loglamayın.
- Uygulama/kullanıcı bazlı abuse kontrolü ekleyin.
- PNG content-type ve imzasını doğrulayın.