-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
42 lines (33 loc) · 1.39 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
41
42
/* Main application entry file. Please note, the order of loading is important.
| * Configuration loading and booting of controllers and custom error handlers */
var express = require('express'),
fs = require('fs');
require('coffee-script');
// Load configurations
var config_file = require('yaml-config'),
exports = module.exports = config = config_file.readConfig('./config.yaml');
require('./db-connect'); // Bootstrap db connection
// Bootstrap models
var models_path = __dirname + '/app/models';
var model_files = fs.readdirSync(models_path);
model_files.forEach(function(file){
if (file == 'user.js')
User = require(models_path+'/'+file);
else
require(models_path+'/'+file);
});
var app = express.createServer(); // express app
require('./settings').boot(app); // Bootstrap application settings
// Start the app by listening on <port>
var port = process.env.PORT || 3000;
app.listen(port);
console.log('Express app started on port '+port);
// Bootstrap controllers
var controllers_path = __dirname + '/app/controllers';
var controller_files = fs.readdirSync(controllers_path);
controller_files.forEach(function(file){
require(controllers_path+'/'+file)(app);
});
require('./error-handler').boot(app); // Bootstrap custom error handler
mongooseAuth.helpExpress(app); // Add in Dynamic View Helpers
everyauth.helpExpress(app, { userAlias: 'current_user' });