-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (49 loc) · 1.53 KB
/
app.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
51
52
53
54
55
56
57
/**
* ApplicationServer
* (Do not change this code)
* Require Modules to setup the REST Api
* - `express` Express.js is a Web Framework
* - `morgan` Isn't required but help with debugging and logging
* - `body-parser` This module allows to parse the body of the post request into a JSON
*/
const express = require("express");
const morgan = require("morgan");
const bodyParser = require("body-parser");
/**
* Require the Blockchain class. This allow us to have only one instance of the class.
*/
const BlockChain = require('./src/blockchain.js');
class ApplicationServer {
constructor() {
//Express application object
this.app = express();
//Blockchain class object
this.blockchain = new BlockChain.Blockchain();
//Method that initialized the express framework.
this.initExpress();
//Method that initialized middleware modules
this.initExpressMiddleWare();
//Method that initialized the controllers where you defined the endpoints
this.initControllers();
//Method that run the express application.
this.start();
}
initExpress() {
this.app.set("port", 8000);
}
initExpressMiddleWare() {
this.app.use(morgan("dev"));
this.app.use(bodyParser.urlencoded({extended:true}));
this.app.use(bodyParser.json());
}
initControllers() {
require("./BlockchainController.js")(this.app, this.blockchain);
}
start() {
let self = this;
this.app.listen(this.app.get("port"), () => {
console.log(`Server Listening for port: ${self.app.get("port")}`);
});
}
}
new ApplicationServer();