-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
47 lines (45 loc) · 1.59 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
const express = require ('express')
const path = require('path')
const PORT = process.env.PORT || 5002
const bodyParser = require('body-parser')
const {callback} = require("chart.js/helpers");
express()
.use(express.static(path.join(__dirname, 'dist')))
.use(bodyParser.urlencoded({extended: true}))
.use(bodyParser.json())
.set('views', path.join(__dirname, 'dist'))
.set('view engine', 'html')
.get('/', (req, res)=>{
console.log("Entry point");
res.render('index.html');
})
.get('/test_api', (req, res)=>{
console.log("test_api");
res.status(200).send('OK');
})
.get('/get_bitcoin_price', (req, res)=>{
console.log("get_bitcoin_price");
const btc = require('./server/bitcoinController');
btc.getBitcoinPrice(function (price) {
res.status(200).send(price);
});
})
.get('/test_get_api_key', (req, res)=>{
console.log("get_api_key");
const key = require('./server/apiKeyController');
res.status(200).send(key.generateApiKey());
})
.post('/test_add_orders', (req, res)=> {
let body = req.body;
const oc = require('./server/orderscontroller');
oc.addOrders(body, req, (rowcount, errorMsg)=> {
if (rowcount > 0){
res.status(200).send('Orders submitted pending payment confirmation');
} else {
if (errorMsg != undefined){
res.status(404).send('Orders not sent');
}
}
});
})
.listen(PORT, ()=> console.log(`Listening on ${ PORT }`));