This repository has been archived by the owner on May 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (36 loc) · 1.47 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
43
44
45
/* 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')
var rest = require('restler')
var sys = require('util')
var fs = require('fs')
utils = require('./lib/utils')
auth = require('./authorization')
// Load configurations
var config_file = require('yaml-config')
exports = module.exports = config = config_file.readConfig('config/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
// 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' })
// Start the app by listening on <port>
var port = process.env.PORT || 3000
app.listen(port)
console.log('Express app started on port '+port)