var mongoose = require('mongoose'),
	mongooseTypes = require('mongoose-types'),
	expressMongoose = require('express-mongoose'),
	passport = require('passport'),
	routes = require('../routes'),
	flash = require('connect-flash'),
	session = require('express-session'),
	log = require('./logger');
    MongoDBStore = require('connect-mongodb-session')(session);
// Database connection bootstrap
module.exports = function(app)
{
	log.info('Springroll API is now operational');

	// Attempt to connect to database
	mongoose.connect(process.env.MONGO_DATABASE, function()
	{
		// Include models once
		require('../models/release');
		require('../models/game');
		require('../models/group');
		require('../models/user');
	});

	// Load the types for URL and Email
	mongooseTypes.loadTypes(mongoose);

	// Listen for errors
	var db = mongoose.connection;
	db.on('error', function(err)
	{
		console.error(String("Connection error : " + err).red);
	});
    
    var store = new MongoDBStore(
        {
            uri: process.env.MONGO_DATABASE,
            collection: 'auth_sessions'
        }
    );

	// Authentication stuff
	app.use(session(
	{
		secret: process.env.SECRET_KEY,
		saveUninitialized: true,
		resave: true,
        store: store
                                       
	}));
	app.use(flash());
	app.use(passport.initialize());
	app.use(passport.session());
	require('./auth')(passport);

	// Load all the routes
	routes(app);
};

@@ -288,20 +288,18 @@
 gger');%0A
-    
+%09%09
 MongoDBS
@@ -350,16 +350,184 @@
 ssion);%0A
+%09%09%0AnotForApi = function (fn) %7B%0A%09return function(req, res, next) %7B%0A%09%09%09if (req.path.indexOf('/api') === 0) %7B%0A%09%09%09%09%09next();%0A%09%09%09%7D else %7B%0A%09%09%09%09%09fn(req, res, next);%0A%09%09%09%7D%0A%09%7D%0A%7D%0A%0A
 // Datab
@@ -1288,16 +1288,26 @@
 app.use(
+notForApi(
 session(
@@ -1452,16 +1452,17 @@
    %0A%09%7D))
+)
 ;%0A%09app.u
@@ -1468,16 +1468,26 @@
 use(
+notForApi(
 flash())
 ;%0A%09a
@@ -1482,16 +1482,17 @@
 flash())
+)
 ;%0A%09app.u
@@ -1486,32 +1486,42 @@
 h()));%0A%09app.use(
+notForApi(
 passport.initial
@@ -1526,16 +1526,17 @@
 alize())
+)
 ;%0A%09app.u
@@ -1538,16 +1538,26 @@
 app.use(
+notForApi(
 passport
@@ -1567,16 +1567,17 @@
 ssion())
+)
 ;%0A%09requi

add a wrapper function to only use session creation middleware on non-API endpoints