forked from RebootJeff/phone-tag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
61 lines (49 loc) · 1.46 KB
/
server.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
55
56
57
58
59
60
61
/**
* Module dependencies.
*/
var express = require('express');
var path = require('path');
var fs = require('fs');
var mongoose = require('mongoose');
var passport = require('passport');
var FacebookStrategy = require('passport-facebook').Strategy;
var app = express();
var io = require('socket.io');
var env = process.env['NODE_ENV'] || 'development';
var credentials;
switch(env){
case "development":
credentials = require('./config/credentials')[env];
break;
case "test":
credentials = require('./config/credentials')[env];
break;
case "production":
credentials = require('./config/productionCredentials')[env];
break;
}
// models
var models_path = __dirname + '/app/models';
fs.readdirSync(models_path).forEach(function(file){
if (~file.indexOf('.js')) require(models_path + '/' + file);
});
// passport-facebook
require('./config/passport')(passport, FacebookStrategy, credentials);
// app environment configuration
require('./config/environments')(app, passport);
// routes
require('./config/routes')(app, passport);
// database connection
mongoose.connect(credentials.db);
// development only
if( app.get('env') === 'development' ) {
app.use(express.errorHandler());
}
// runs the server
var port = process.env.PORT || 3000;
console.log("Express application is listening to port", port);
var socket = app.listen(port);
var ioObj = io.listen(socket);
// socket connection
require('./config/socket/socket')(ioObj);
module.exports = app;