Capture from a Nitro server route
The public client never receives the provider key, and the server resolves a known page path.
export default defineEventHandler(async (event) => {
const { pageId } = await readBody(event);
const pages = {
pricing: "https://example.com/pricing",
docs: "https://example.com/docs",
};
const url = pages[pageId];
if (!url) {
throw createError({ statusCode: 400, statusMessage: "Unknown page" });
}
const config = useRuntimeConfig(event);
return await $fetch(
"https://api.prod.ss.snapshot-site.com/api/v1/screenshot",
{
method: "POST",
headers: {
"x-snapshotsiteapi-key": config.snapshotSiteApiKey,
},
body: {
url,
format: "webp",
width: 1440,
height: 900,
fullSize: true,
hideCookie: true,
},
},
);
});
