-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (31 loc) · 915 Bytes
/
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
const express = require('express');
const QRCode = require('qrcode');
const { exec } = require('child_process');
const app = express();
app.use(express.json());
app.use(express.static('public'));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
app.post('/generateQR', (req, res) => {
const { text } = req.body;
QRCode.toDataURL(text, (err, url) => {
if (err) return console.error(err);
res.send({ url });
});
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
// Open the default web browser
switch (process.platform) {
case 'darwin':
exec(`open http://localhost:${PORT}`);
break;
case 'win32':
exec(`start http://localhost:${PORT}`);
break;
default:
exec(`xdg-open http://localhost:${PORT}`);
}
});