/**
 * Module dependencies.
 */

var express = require('express')
var http = require('http')
var path = require('path')
var MongoClient = require('mongodb').MongoClient
var async = require('async')
var MongoStore = require('connect-mongo')(express);
var configurePassport = require('./lib/configure-passport');
var dbSingleton = require('./lib/db');

var server;
module.exports.startServer = function (port, dbUrl, configRoute, callback) {
    var app = express();
    server = require('http').createServer(app);

    async.waterfall([
        function (callback) {
            MongoClient.connect(dbUrl, callback);
        },
        function (db, callback) {

            dbSingleton.setDb(db);
            app.set('port', port);
            app.use(express.favicon());
            app.use(express.logger('dev'));
            app.use(express.urlencoded());
            app.use(express.json());
            app.use(express.methodOverride());

            app.use(express.cookieParser('some secret'));
            app.use(express.session({
                secret: '1GSrN6oX8cvEzfeecNqm3xgfZZZBj6DQpY',
                store: new MongoStore({
                    db: db
                })
            }));

            if ('development' == app.get('env')) {
                app.use(express.errorHandler());
            }

            configurePassport(app, db);
            configRoute(app, callback);
        },
        function(callback) {


            app.use(app.router);

            server.listen(app.get('port'), callback);
        }
    ], function (err, result) {
        callback(err);
    });
};

module.exports.close = function (callback) {
    server.close(callback);
};


@@ -769,52 +769,8 @@
 ));%0A
-            app.use(express.logger('dev'));%0A
     
@@ -1251,24 +1251,72 @@
 Handler());%0A
+                app.use(express.logger('dev'));%0A
             
@@ -1317,16 +1317,16 @@
       %7D%0A
-
 %0A       
@@ -1438,18 +1438,16 @@
 back) %7B%0A
-%0A%0A
         
@@ -1471,16 +1471,86 @@
 outer);%0A
+            console.log('starting server on port ' + app.get('port'));
 %0A       

enable dev logging only on dev builds