-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (23 loc) · 834 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
var express = require('express');
var QRCode = require('qrcode');
var app = express();
app.use(express.static('public'));
app.get("/", function (request, response) {
response.sendFile(__dirname + '/views/index.html');
});
function totp(res, name, secret) {
var qrQata = `otpauth://totp/${encodeURIComponent(name)}?secret=${encodeURIComponent(secret)}`;
QRCode.toFileStream(res, qrQata);
}
app.get("/totp/:name/:secret", function (req, res) {
totp(res, req.params.name, req.params.secret)
});
app.get("/totp/:name", function (req, res) {
totp(res, req.params.name, req.query.secret);
});
app.get("/totp", function (req, res) {
totp(res, req.query.name, req.query.secret);
});
var listener = app.listen(process.env.PORT, function () {
console.log('Your app is listening on port ' + listener.address().port);
});