-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
62 lines (52 loc) · 1.52 KB
/
index.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const express = require("express");
const path = require("path");
const {
generateQRCodeFromData,
showLoader,
hideLoader,
} = require("./src/QrCode.js");
const QRCode = require("qrcode");
const app = express();
const port = 3000;
app.use(express.json());
app.use(express.static(path.join(__dirname, "public")));
app.use(express.urlencoded({ extended: true }));
app.get("/api/qrgen", async (req, res) => {
const { data, url, name, phoneNum, org, address } = req.query;
try {
let qrData;
if (data) {
qrData = `${data}`;
} else if (url) {
qrData = `${url}`;
} else if (name || phoneNum || address || org) {
qrData = `BEGIN:VCARD
VERSION:3.0
FN:${name || ''}
TEL:${phoneNum || ''}
ADR:${address || ''}
ORG:${org || ''}
END:VCARD`;
} else {
return res.status(400).send("Missing required data");
}
const qrCodeBuffer = await QRCode.toBuffer(qrData);
res.type("png").send(qrCodeBuffer);
} catch (error) {
console.error("Error generating QR code:", error);
res.status(500).send("Error generating QR code");
}
});
//new redirects
app.get('/qrgen', (req, res) => {
res.redirect('https://multi-qr-code-generator.vercel.app/');
});
app.get('/api', (req, res) => {
res.redirect('https://multi-qr-code-generator.vercel.app/api');
});
app.get('/', (req, res) => {
res.redirect('https://multi-qr-code-generator.vercel.app/');
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});