Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiixInc authored Aug 14, 2022
1 parent f5e9873 commit 2c8c56d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getScreenshot } from "./_lib/puppeteer";

module.exports = async (req, res) => {
if (!req.query.url) return res.status(400).send("No url query specified.");
if (!checkUrl(req.query.url, req.hostname)) return res.status(400).send("Invalid url query specified.");
try {
const file = await getScreenshot(req.query.url, req.query.width, req.query.height);
res.setHeader("Content-Type", "image/png");
Expand All @@ -12,3 +13,14 @@ module.exports = async (req, res) => {
res.status(500).send("The server encountered an error. You may have inputted an invalid query.");
}
}

function checkUrl(string, hostname) {
var url = "";
try {
url = new URL(string);
} catch (error) {
return false;
}
if (url.hostname == hostname) return false;
return true;
}

1 comment on commit 2c8c56d

@vercel
Copy link

@vercel vercel bot commented on 2c8c56d Aug 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

screenshot – ./

screenshot-git-main-remiixinc.vercel.app
screenshot-remiixinc.vercel.app
s.vercel.app

Please sign in to comment.