From 9a14cc9df34b7d34f03f80f3524e10e0436c3fd6 Mon Sep 17 00:00:00 2001 From: Danny Spina Date: Mon, 19 Jun 2023 01:22:20 +0200 Subject: [PATCH] Add handling incomlete urls --- index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index f456523..45895a6 100644 --- a/index.ts +++ b/index.ts @@ -14,12 +14,19 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); app.get("/", (req, res) => { - const url = req.query.at as string; + let url = req.query.at as string; if (!url) { res.sendFile(path.join(__dirname + "/dist/index.html")); } + var re = new RegExp("^(http|https)://", "i"); + var match = re.test(url); + + if (!match) { + url = `https://${url}` + } + got(url) .then((response) => { const dom = new JSDOM(response.body);