Files
meanTorrent/server.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

2013-05-22 17:03:50 +03:00
/**
* Module dependencies.
*/
2013-08-17 01:06:17 +03:00
var express = require('express'),
fs = require('fs'),
passport = require('passport'),
logger = require('mean-logger');
2013-05-22 17:03:50 +03:00
/**
* Main application entry file.
* Please note that the order of loading is important.
*/
2013-08-17 01:06:17 +03:00
//Load configurations
//if test env, load example file
2013-09-10 12:36:19 +03:00
var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development',
config = require('./config/config'),
2013-08-17 01:06:17 +03:00
auth = require('./config/middlewares/authorization'),
mongoose = require('mongoose');
2013-05-22 17:03:50 +03:00
2013-08-17 01:06:17 +03:00
//Bootstrap db connection
var db = mongoose.connect(config.db);
2013-05-22 17:03:50 +03:00
2013-08-17 01:06:17 +03:00
//Bootstrap models
var models_path = __dirname + '/app/models';
2013-09-29 16:00:23 +03:00
var walk = function(path) {
fs.readdirSync(path).forEach(function(file) {
var newPath = path + '/' + file;
var stat = fs.statSync(newPath);
if (stat.isFile()) {
if (/(.*)\.(js|coffee)/.test(file)) {
require(newPath);
}
} else if (stat.isDirectory()) {
walk(newPath);
}
});
2013-09-27 23:37:20 -04:00
};
walk(models_path);
2013-05-22 17:03:50 +03:00
2013-08-17 01:06:17 +03:00
//bootstrap passport config
2013-09-10 12:36:19 +03:00
require('./config/passport')(passport);
2013-05-22 17:03:50 +03:00
2013-08-17 01:06:17 +03:00
var app = express();
2013-08-17 01:06:17 +03:00
//express settings
require('./config/express')(app, passport, db);
2013-05-22 17:03:50 +03:00
2013-08-17 01:06:17 +03:00
//Bootstrap routes
require('./config/routes')(app, passport, auth);
2013-05-22 17:03:50 +03:00
2013-08-17 01:06:17 +03:00
//Start the app by listening on <port>
2013-09-10 12:36:19 +03:00
var port = config.port;
2013-08-17 01:06:17 +03:00
app.listen(port);
console.log('Express app started on port ' + port);
2013-05-22 17:03:50 +03:00
2013-09-27 23:37:20 -04:00
//Initializing logger
2013-08-17 01:06:17 +03:00
logger.init(app, passport, mongoose);
2013-06-23 20:53:56 +03:00
2013-08-17 01:06:17 +03:00
//expose app
exports = module.exports = app;