
// TODO: Find a better way to load different configs in different env
var dbConfig;
try {
    // Look for dev conf for local development
    dbConfig = require('./config/db.dev.conf.js');
} catch(e) {
    try {
        // production conf?
        dbConfig = require('./config/db.conf.js');
    } catch(e) {
        console.log('Startup failed.  No db config file found.');
        return false;
    }
}


var knex = require('knex')({
        client: 'mysql',
        connection: dbConfig
    }),
    Memcached = require('memcached'),
    express = require('express'),
    bodyParser = require('body-parser'),
    cookieParser = require('cookie-parser'),
    cookieSession = require('cookie-session'),
    serveStatic = require('serve-static'),
    expressValidator = require('express-validator'),
    flash = require('connect-flash'),
    swig = require('swig'),
    passport = require('passport'),
    crypto = require('crypto'),
    Bookshelf = require('bookshelf'),
    kue = require('kue'),
    //queue = kue.createQueue(),
    messages = require('./util/messages');

var memcached = new Memcached('ec2-35-167-10-53.us-west-2.compute.amazonaws.com:11211');
var app = express();
app.knexRef = knex;
app.memcacheRef = memcached;
app.queRef = queue || 0;
app.memcacheRef = memcached;

Bookshelf.mysqlAuth = Bookshelf(knex);

app.use(cookieParser('halsisiHHh445JjO0'));
app.use(cookieSession({
    keys: ['key1', 'key2']
}));

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use(expressValidator());
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(serveStatic('./public'));
//app.use(express.favicon(__dirname + '/public/images/shortcut-icon.png'));
app.use(messages());

app.engine('html', swig.renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');

require('./util/auth')(passport);
require('./routes')(app, passport);

app.listen(process.env.PORT || 8989);

console.log('Listening on port 8989');

@@ -1282,17 +1282,8 @@
 ef =
- queue %7C%7C
  0;%0D

Fix :@