Public
Express
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Buffer } from "node:buffer";
export async function qr(req: express.Request, res: express.Response) {
if (req.path.startsWith("/qr")) {
const { qrcode } = await import("https://deno.land/x/qrcode/mod.ts");
const base64Image = await qrcode(req.query.data);
res.set("content-type", "image/gif");
res.send(
Buffer.from(base64Image.replace("data:image/gif;base64,", ""), "base64"),
);
}
else {
res.send(`<html>
<div>
<img src="/qr?data=https://stevekrouse-qr.express.val.run" style="width:500px">
</img>
<input type="text" />
</div>
<script>
let img = document.getElementsByTagName("img")[0]
let input = document.getElementsByTagName("input")[0]
input.addEventListener('input', function(e){
img.src="/qr?data=" + e.target.value
})
</script>
</html>
`);
}
}
// Forked from @ramkarthik.GenerateQR
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
stevekrouse-qr.express.val.run
October 23, 2023