-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
79 lines (68 loc) · 2.21 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const path = require("path");
const express = require("express");
const hbs = require("hbs");
const requestIp = require("request-ip");
const initWallets = require("./modules/wallets");
async function main() {
const wallets = await initWallets(true);
hbs.registerPartials(path.join(__dirname, "/views/partials"));
const app = express();
app.set("view engine", "hbs");
app.use("", express.static("static"));
app.get("/:walletId/widget", (req, res) => {
try {
const walletId = req.params.walletId || "default";
const wallet = wallets[walletId] || wallets["default"];
if (wallet) {
res.render("pages/widget.hbs", {
walletId,
revealDelayMsec: wallet.revealDelayMsec,
revealDelay2Msec: wallet.revealDelay2Msec,
isTransparentBg: !!req.query.isTransparentBg
});
} else {
res.status(404).render("pages/404.hbs");
}
} catch (e) {
res.status(500).render("pages/500.hbs");
}
});
app.get("/:walletId.json", [requestIp.mw()], (req, res) => {
try {
const walletId = req.params.walletId || "default";
const wallet = wallets[walletId] || wallets["default"];
const address = wallet.generateAddress(req.clientIp);
if (wallet) {
res.json({ address, walletId });
} else {
res.status(404).json({ error: true });
}
} catch (e) {
res.status(500).json({ error: true });
}
});
app.get("/:walletId?", (req, res) => {
try {
const walletId = req.params.walletId || "default";
const wallet = wallets[walletId] || wallets["default"];
if (wallet) {
res.render("pages/page.hbs", {
walletId,
revealDelayMsec: wallet.revealDelayMsec,
revealDelay2Msec: wallet.revealDelay2Msec,
pageData: wallet.page
});
} else {
res.status(404).render("pages/404.hbs");
}
} catch (e) {
res.status(500).render("pages/500.hbs");
}
});
const SERVER_PORT = process.env.SERVER_PORT || 4000;
const SERVER_HOST = process.env.SERVER_HOST || "localhost";
app.listen(SERVER_PORT, SERVER_HOST, () => {
console.log(`*** I'm listening on ${SERVER_HOST}:${SERVER_PORT} ***`);
});
}
main();