aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'server.js')
-rw-r--r--server.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/server.js b/server.js
new file mode 100644
index 0000000..e30b9ee
--- /dev/null
+++ b/server.js
@@ -0,0 +1,66 @@
+
+/**
+ * Module dependencies.
+ */
+
+var express = require('express')
+ , fs = require('fs')
+ , passport = require('passport')
+ , mongoose = require('mongoose');
+
+
+/**
+ * App configuration
+ */
+
+var port = process.env.PORT || 8000
+ , env = process.env.NODE_ENV || 'development'
+ , config = require('./config/config')[env]
+ , auth = require('./config/middlewares/authorization');
+
+
+// Bootstrap db connection
+mongoose.connect(config.db);
+var db = mongoose.connection;
+db.on('error', console.error.bind(console, 'connection error:'));
+db.once('open', function callback(){
+ console.log('Connected to ' + config.db);
+});
+
+
+// Bootstrap models
+// This gets all model files in ./app/models
+var models_path = __dirname + '/app/models';
+fs.readdirSync(models_path).forEach( function(file) {
+ require(models_path + '/' + file);
+});
+
+
+// Bootstrap passport config
+require('./config/passport')(passport, config);
+
+
+/**
+ * Express
+ */
+
+var app = express();
+// express settings
+require('./config/express')(app, config, passport);
+
+
+/**
+ * Routes
+ */
+
+require('./config/routes')(app, passport, auth);
+
+
+/**
+ * Server initiation
+ */
+
+app.listen(port, function() {
+ console.log("Express server listening on port " + port);
+});
+