Skip to content

Instantly share code, notes, and snippets.

@5t111111
Created June 22, 2021 03:22
Show Gist options
  • Save 5t111111/0829b5674237424c81570c8620479a0f to your computer and use it in GitHub Desktop.
Save 5t111111/0829b5674237424c81570c8620479a0f to your computer and use it in GitHub Desktop.
Simple QRCode generator for Deno Deploy
/**
* 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