Capture a known application page
The route maps a page ID to a trusted URL and never accepts the provider key from the client.
import express from "express";
const app = express();
app.use(express.json());
const pages = new Map([
["pricing", "https://example.com/pricing"],
["docs", "https://example.com/docs"],
]);
app.post("/captures", async (req, res) => {
const url = pages.get(req.body.pageId);
if (!url) return res.status(400).json({ error: "Unknown page" });
const response = await fetch(
"https://api.prod.ss.snapshot-site.com/api/v1/screenshot",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-snapshotsiteapi-key": process.env.SNAPSHOT_SITE_API_KEY,
},
body: JSON.stringify({
url,
format: "webp",
width: 1440,
height: 900,
fullSize: true,
hideCookie: true,
}),
},
);
const body = await response.json();
return res.status(response.ok ? 200 : 502).json(body);
});
