-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
64 lines (56 loc) · 1.93 KB
/
app.js
File metadata and controls
64 lines (56 loc) · 1.93 KB
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
var path = require('path');
var express = require('express');
var app = express();
var Config = require('./config')();
var Utilities = require("./utilities")();
var Blockchain = require("./blockchain")(Config, Utilities);
// Display available BAB and ETH funds in the server wallet at startup
Blockchain.getBABBalance(Config.getServerWallet()).then((result) => {
Utilities.log("Server wallet BAB funds : " + result);
});
Blockchain.getETHBalance(Config.getServerWallet()).then((result) => {
Utilities.log("Server wallet ETH funds : " + result);
});
// Support for JSON-encoded POST parameters
app.use(express.json({limit : '50mb'}))
app.use(express.urlencoded({extended : true}))
// Handle all API routes with the routers defined in ./routes
var routes = require("./routes")(Config, Utilities, Blockchain)
app.use('/api', routes)
// Serve client code
const publicFolder = path.join(__dirname, "public");
app.set('views', publicFolder);
app.set('view engine', 'ejs');
// Render pages using EJS templates
app.get("/", function(req,res) {
res.render("pages/index");
});
app.get("/api", function(req,res) {
res.render("pages/apiDoc");
});
app.get("/BABHolders", function(req,res) {
res.render("pages/BABHolders");
});
app.get("/BABTransactions", function(req,res) {
res.render("pages/BABTransactions");
});
app.get("/virements", function(req,res) {
res.render("pages/virements");
});
app.get("/BABWhales", function(req,res) {
res.render("pages/BABWhales");
});
app.use('/', express.static(publicFolder));
app.use('/', function(req, res)
{
res.sendFile(path.join(publicFolder, "index.html"));
});
// Create the HTTP server
var http = require("http");
server = http.createServer(app);
// Start the HTTP server
var listeningServer = server.listen(Config.getServerPort(), Config.getServerIP(), function () {
var host = listeningServer.address().address
var port = listeningServer.address().port
Utilities.log("Listening on https://" + host + ":" + port)
});