forked from Siko91/BitBoxDemo-23Oct18
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (33 loc) · 1022 Bytes
/
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
var express = require('express');
var fs = require('fs');
var bitcoin = require('./bitcoin.js');
var priceConverter = require('./priceConverter.js');
var products = require('./products.json');
var notPaid = fs.readFileSync('notPaid.html', 'utf8');
var paid = fs.readFileSync('paid.html', 'utf8');
var app = express()
var port = 3000
app.get('/', (req, res) =>
res.send(`Select Product :
<ul>` +
products
.map(p=>p.name)
.map(p=>'<li><a href="/' + p + '">' + p + '</a></li>')
.join("")
+ `<ul>`)
);
products.forEach(p=>{
app.get('/' + p.name, (req, res) => {
priceConverter.convertFiatToBCH(p.price, p.currency, function convertionCallback(bchPrice) {
bitcoin.checkIsPaid(p.name + req.ip, bchPrice,
function paidCallback() {
res.send(paid.replace('#data', p.data))
},
function notPaidCallback(addr) {
res.send(notPaid.replace('#addr', addr).replace('#price', bchPrice))
}
)
});
})
});
app.listen(port, () => console.log(`App listening on port ${port}!`));