-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (36 loc) · 1.16 KB
/
server.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
// BISMILLAH
const express = require("express");
const app = express();
const path = require("path");
const bodyParser = require("body-parser");
const qrCode = require("qrcode");
const port = process.env.PORT || 9000;
app.set("view engine", "pug");
app.set("views", path.join(__dirname, "views"));
app.use(express.static(path.join(__dirname, "templates")));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Home Route
app.get("/", (req, res) => {
res.status(200).render("base", { title: "QR Application!" });
console.log("hi, it working!");
});
// Post (input)
app.post("/getQRcode", (req, res, err) => {
if (!req.body.QRtext) {
res.render("emptyData", { title: "Empty Data!" });
} else if (req.body.QRtext) {
let textData = req.body.QRtext;
qrCode.toDataURL(
textData, { type: "terminal", quality: 0.9 },
(err, url) => {
if (err) res.send(err.message);
res.render("qrContainer", { data: url, title: "Your QRcode!" });
console.log(url);
}
);
}
});
app.listen(port, () => {
console.log("Hello from server!");
});