-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (41 loc) · 1.24 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
'use strict';
// Set default node environment to development
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var express = require('express'),
path = require('path'),
fs = require('fs');
/**
* Main application file
*/
// Application Config
var config = require('./lib/config/config');
// Load custom errors
require('./lib/config/errors');
// Passport Configuration
var passport = require('./lib/config/passport');
// Express app
var app = express();
// Bootstrap models
var db = require('./lib/models');
// Express settings
require('./lib/config/express')(app, passport);
// Bootstrap routes
var routesPath = path.join(__dirname, 'lib/routes');
fs.readdirSync(routesPath).forEach(function (file) {
if (/(.*)\.(js$)/.test(file)) {
require(routesPath + '/' + file)(app);
}
});
// html5mode on in angular. Needs to be after bootstrapping the routes.
require('./lib/angular')(app);
db.sequelize.authenticate().then(function() {
// Start server
app.listen(config.port, function () {
console.log('Express server listening on port %d in %s mode', config.port, app.get('env'));
});
}, function(err) {
console.log('Error authenticating the database', err);
throw(err);
});
// Expose app
exports = module.exports = app;