-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (31 loc) · 1.2 KB
/
app.js
File metadata and controls
40 lines (31 loc) · 1.2 KB
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
var express = require('express'),
anyDB = require('any-db'),
moment = require('moment'),
_ = require('underscore');
// Config
var smn = {
ip_address: process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0',
port: process.env.OPENSHIFT_NODEJS_PORT || 8080,
dbURL: 'postgres://user:password@localhost:5432/smn'
};
// create app
var app = express();
// enable gzip compression
app.use(express.compress());
// create DB connection pool
var pool = anyDB.createPool(smn.dbURL, {min: 2, max: 10});
app.listen(smn.port, smn.ip_address, function () {
console.log('[%s] Node server started on %s:%d, (%s minutes from UTC) ...', moment.utc().format(), smn.ip_address, smn.port, moment().zone());
// Modules to load (and the order to load them in)
var modules = [ 'parameters', 'cors', 'outstations', 'reports', 'feed' ];
// Load each module
_.each(modules, function (moduleName) {
loadModule(moduleName, app, pool);
});
});
// Load a module and pass it an instance of the app and DB pool
function loadModule (moduleName, app, pool) {
var fileName = __dirname + '/modules/' + moduleName;
console.log('Loading module: [%s]', fileName);
require(fileName)(app, pool);
}