Created
June 22, 2021 03:22
-
-
Save 5t111111/0829b5674237424c81570c8620479a0f to your computer and use it in GitHub Desktop.
Simple QRCode generator for Deno Deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simple QRCode generator for Deno Deploy | |
*/ | |
import { qrcode } from "https://deno.land/x/qrcode/mod.ts"; | |
addEventListener("fetch", async (event) => { | |
const url = new URL(event.request.url); | |
const params = new URLSearchParams(url.search); | |
const text = params.get("text"); | |
if (!text) { | |
const response = new Response("text must be specified.", { | |
headers: { "content-type": "text/plain" }, | |
}); | |
event.respondWith(response); | |
return; | |
} | |
const base64 = await qrcode(text, { size: 1080 }); | |
const html = `<img src="${base64}" />`; | |
const response = new Response(html, { | |
headers: { "content-type": "text/html" }, | |
}); | |
event.respondWith(response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment