-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (29 loc) · 1014 Bytes
/
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
const express = require('express');
const fs = require('fs');
const passport = require('passport');
const env = process.env.NODE_ENV || 'development';
const config = require('./config/config')[env];
const auth = require('./config/middlewares/authorization');
const mongoose = require('mongoose');
const app = express();
const port = process.env.PORT || 3000;
const http = require('http').Server(app);
const io = require('socket.io')(http);
mongoose.Promise = global.Promise;
mongoose.connect(config.db, {
keepAlive: true,
reconnectTries: Number.MAX_VALUE,
useMongoClient: true
});
const models_path = __dirname + '/app/models';
fs.readdirSync(models_path).forEach(file => {
require(models_path + '/' + file);
});
require('./config/passport')(passport, config);
require('./config/express')(app, config, passport);
require('./config/routes')(app, passport, auth);
require('./config/sockets')(io);
app.listen(port);
http.listen(4000);
console.log('Express app started on port ' + port);
module.exports = app;