-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (32 loc) · 1.12 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
var express = require( 'express' );
var bodyParser = require( 'body-parser' );
var compression = require( 'compression' );
var config = require( './config' );
var loadRoutes = require( './lib/loadRoutes.js' );
var renderPage = require( './lib/renderPage' );
var logger = require( './lib/logger' );
var app = express();
var MongoClient = require('mongodb').MongoClient;
// Connection URL
var url = process.env.MONGOLAB_URI ?
process.env.MONGOLAB_URI :
'mongodb://' + config.mongodb.url + '/' + config.mongodb.database;
// Use connect method to connect to the Server
MongoClient.connect(
url,
function( err, db ) {
app.set( 'db', db );
app.use( bodyParser.urlencoded({ extended: true }) );
app.set( 'config', config );
app.set( 'logger', logger );
app.set( 'bouncers', {} );
app.set(
'helper', { renderPage: renderPage }
);
app.use( compression() );
app.use( express.static( __dirname + '/public', { maxAge : 31536000000 } ) );
loadRoutes( app );
console.log( 'listening to port:' + config.port );
app.listen( config.port );
}
);