var express = require("express"); var router = express.Router(); const QRCode = require("qrcode"); /* GET home page. */ router.get("/", function (req, res, next) { res.render("index", { title: "Express" }); }); router.get("/code", async function (req, res, next) { const code = Math.random().toString(36).substring(2, 8); // random code const qrUrl = `/api/v1/code/${code}?amount=1&service=software%20service`; const qrData = await QRCode.toDataURL( `http://localhost:${process.env.PORT || 3000}${qrUrl}` ); res.render("code", { qrData, qrUrl: `http://localhost:${process.env.PORT || 3000}${qrUrl}`, }); }); module.exports = router;