Skip to content

Commit 1f5151b

Browse files
authored
Update screenshot.ts
1 parent 09b85e1 commit 1f5151b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

api/screenshot.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import { NowRequest, NowResponse } from '@vercel/node'
22

33
module.exports = (req: NowRequest, res: NowResponse) => {
4-
res.status(200).send("hey")
4+
try {
5+
const file = await getScreenshot(req.query.url, req.query.width, req.query.height);
6+
res.header('Content-Type', `image/png`);
7+
res.header('Cache-Control', `public, immutable, no-transform, s-maxage=31536000, max-age=31536000`);
8+
res.status(200).end(file);
9+
} catch (error) {
10+
res.header('Content-Type', 'application/json');
11+
res.json({
12+
"success": false,
13+
"error": "No url query",
14+
"usage": "https://screenshot.totallyusefulapi.ml/api?url=https://totallyusefulapi.ml&width=1920&height=180"
15+
});
16+
}
517
}

0 commit comments

Comments
 (0)