Skip to content

Commit 2c8c56d

Browse files
authored
Update index.ts
1 parent f5e9873 commit 2c8c56d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

api/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getScreenshot } from "./_lib/puppeteer";
22

33
module.exports = async (req, res) => {
44
if (!req.query.url) return res.status(400).send("No url query specified.");
5+
if (!checkUrl(req.query.url, req.hostname)) return res.status(400).send("Invalid url query specified.");
56
try {
67
const file = await getScreenshot(req.query.url, req.query.width, req.query.height);
78
res.setHeader("Content-Type", "image/png");
@@ -12,3 +13,14 @@ module.exports = async (req, res) => {
1213
res.status(500).send("The server encountered an error. You may have inputted an invalid query.");
1314
}
1415
}
16+
17+
function checkUrl(string, hostname) {
18+
var url = "";
19+
try {
20+
url = new URL(string);
21+
} catch (error) {
22+
return false;
23+
}
24+
if (url.hostname == hostname) return false;
25+
return true;
26+
}

0 commit comments

Comments
 (0)