-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (42 loc) · 1.54 KB
/
index.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
'use strict';
var logger = require('./app/lib/logger');
logger.info('Pilum server starting');
var os = require('os');
logger.info('** hostname = ' + os.hostname());
logger.info('** type = ' + os.type());
logger.info('** platform = ' + os.platform());
logger.info('** arch = ' + os.arch());
logger.info('** release = ' + os.release());
logger.info('** uptime = ' + os.uptime());
logger.info('** versions = ' + JSON.stringify(process.versions));
// Configure the app
logger.info('Configuring the app');
var config = require('./app/lib/config');
// Create the express application
logger.info('Starting express');
var express = require('express');
var app = express();
// Establish the database connection
logger.info('Setting up the database connection');
var dbConnection = require('./app/lib/dbConnection');
// Only use request logger for development environment
if (config.app.env === 'development') {
logger.info('Enabling request logging');
var morgan = require('morgan');
app.use(morgan('dev', { stream : logger.stream }));
}
// Set up the static routes
var path = require('path');
app.use(express.static(path.join(__dirname, 'public')));
// Set up the api routes
logger.info('Creating the routes');
var routes = require('./app/routes');
app.use(routes);
// Start the web server
var server = app.listen(config.server.port, function () {
var host = server.address().address;
var port = server.address().port;
logger.info('Listening at http://%s:%s', host, port);
logger.info('Pilum server start up complete');
});
module.exports = app;