-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
41 lines (36 loc) · 1.44 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
module.exports = () => {
// dependencies
const bodyParser = require('body-parser');
const chalk = require('chalk');
const errorHandler = require('errorhandler');
const express = require('express');
const expressStatusMonitor = require('express-status-monitor');
const http = require('http');
const logger = require('morgan');
const path = require('path');
const apiController = require('./controllers/api');
const socketController = require('./controllers/socket');
// configure express
const app = express();
app.set('port', 3000);
app.use(expressStatusMonitor());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, 'public')));
// endpoint definitions
app.get('/exchangePrices', apiController.getExchangePrices);
app.get('/blockchainChartInfo', apiController.getBlockchainChartInfo);
app.get('/latestBlock', apiController.getLatestBlock);
app.get('/unconfirmedTransactions', apiController.getUnconfirmedTransactions);
// error handler
app.use(errorHandler());
// start express
app.listen(app.get('port'), () => {
console.log('%s App is running at http://localhost:%d in %s mode', chalk.green('✓'), app.get('port'), app.get('env'));
console.log(' Press CTRL-C to stop\n');
});
// setup socket listener
let socketListener = http.createServer(app).listen(3001);
socketController(socketListener);
};