aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server.js
blob: e30b9ee12cd6e97e0723641818f64f6525a8a5b7 (plain) (blame)
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
55
56
57
58
59
60
61
62
63
64
65
66

/**
 * Module dependencies.
 */

var express = require('express')
  , fs = require('fs')
  , passport = require('passport')
  , mongoose = require('mongoose');


/**
 * App configuration
 */

var port = process.env.PORT || 8000
  , env = process.env.NODE_ENV || 'development'
  , config = require('./config/config')[env]
  , auth = require('./config/middlewares/authorization');


// Bootstrap db connection
mongoose.connect(config.db);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback(){
    console.log('Connected to ' + config.db);
});


// Bootstrap models
// This gets all model files in ./app/models
var models_path = __dirname + '/app/models';
fs.readdirSync(models_path).forEach( function(file) {
    require(models_path + '/' + file);
});


// Bootstrap passport config
require('./config/passport')(passport, config);


/**
 * Express
 */

var app = express();
// express settings
require('./config/express')(app, config, passport);


/**
 * Routes
 */

require('./config/routes')(app, passport, auth);


/**
 * Server initiation
 */

app.listen(port, function() {
    console.log("Express server listening on port " + port);
});