-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (34 loc) · 1.03 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
require("./utils.js");
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.replaceAll('#data', p.data))
},
function notPaidCallback(addr) {
res.send(notPaid.replaceAll('#addr', addr).replaceAll('#price', bchPrice))
}
)
});
})
});
app.listen(port, () => console.log(`App listening on port ${port}!`));