-
Notifications
You must be signed in to change notification settings - Fork 20
/
server.js
50 lines (42 loc) · 1.07 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
48
49
50
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const Colors = require("colors");
const block = require("./block-watcher");
Colors.setTheme({
styleRed: ["red"],
green: ["green"],
yellow: ["yellow"],
});
const PORT = process.env.PORT || 3032;
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors());
const _startBlock = () => {
return block
.start()
.then(async (success) => {
if (success) {
console.log("Block watcher started successfully".green);
}
})
.catch(async (error) => {
console.log(error);
});
};
(async () => {
Promise.resolve()
.then(_startBlock)
.catch(async (error) => {
const message = `An error occurred while registering block listener ${error}`;
console.error(message);
});
})();
app.get("/ping", function (req, res) {
res.status(200).send("pong");
});
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}.`.green);
});