-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
33 lines (29 loc) · 1.02 KB
/
main.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
/**
* @createdDate: 17 Feb 2017
* @description main.js file which creates a server and listens to
* the port specified.
*/
import express from 'express';
import bodyParser from 'body-parser';
import ejs from 'ejs';
import path from 'path';
import configManager from './server/utils/configManager';
import router from './server/routes';
import log from './server/utils/logger';
const app = express();
const appConfig = configManager.getConfig('app');
const clientDir = path.join(__dirname, appConfig.indexDir);
let port = process.env.PORT || appConfig.port;
let host = appConfig.host;
app.engine('html', ejs.renderFile);
app.set('view engine', 'html');
app.set('views', clientDir);
app.use(express.static(path.join(clientDir, 'static')));
app.use(bodyParser.json());
app.use(router);
const server = app.listen(port, host, () => {
host = server.address().address;
port = server.address().port;
log.info(`Server listening at Host: ${host}, Port: ${port},` +
` Mode: ${configManager.env} mode`);
});