Create a server-side API route
The endpoint validates HTTPS and sends a structured screenshot request without exposing the credential.
export async function POST({ request }) {
const { url } = await request.json();
const target = new URL(url);
if (target.protocol !== "https:") {
return new Response("HTTPS required", { status: 400 });
}
const response = await fetch(
"https://api.prod.ss.snapshot-site.com/api/v1/screenshot",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-snapshotsiteapi-key": import.meta.env.SNAPSHOT_SITE_API_KEY,
},
body: JSON.stringify({
url: target.toString(),
format: "webp",
width: 1440,
height: 900,
fullSize: true,
}),
},
);
return new Response(await response.text(), {
status: response.status,
headers: { "Content-Type": "application/json" },
});
}
