1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// fetch("https://api.val.town/v1/express/ramkarthik.GenerateQR?url={url}"
export async function GenerateQR(req, res) {
const url = req.query.url;
res.set("Content-Type", "text/html");
if (!url) {
res.send(
"<html><body>Not a valid URL - " + JSON.stringify(req.query) +
"</body></html>",
);
}
const { qrcode } = await import("https://deno.land/x/qrcode/mod.ts");
const base64Image = await qrcode(url);
res.send(
`<html><body><img src=${base64Image} height="100px" width="100px" /><p style="font-size:10px">QR Code generated using <a href="https://val.town">val.town</a></p><p style="font-size:10px">Built with &#128151; by <a href="https://twitter.com/Ramkarthik">
);
}