const _ = require('lodash');
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const http = require('http');
const server = http.createServer(app);
const Primus = require('primus');

const db = require('./initDatabase')();
const realtime = require('../realtime');

const primusOptions = {
  transformer: 'engine.io',
};

const io = new Primus(server, primusOptions);
realtime.init(io);

const decodeJwt = require('../middlewares/decode-jwt');
const controllers = require('../controllers');

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

function init() {
  _.extend(this, {
    app,
    server,
    io,
    db,
  });
}

module.exports = init;

@@ -1,12 +1,109 @@
+function init(config = %7B%7D) %7B%0A  const nconf = require('nconf');%0A  const path = require('path');%0A  
 const _ = re
@@ -115,24 +115,26 @@
 ('lodash');%0A
+  
 const expres
@@ -153,24 +153,26 @@
 'express');%0A
+  
 const app = 
@@ -178,24 +178,26 @@
  express();%0A
+  
 const bodyPa
@@ -223,24 +223,26 @@
 y-parser');%0A
+  
 const http =
@@ -255,24 +255,26 @@
 re('http');%0A
+  
 const server
@@ -300,16 +300,18 @@
 r(app);%0A
+  
 const Pr
@@ -333,24 +333,239 @@
 'primus');%0A%0A
+  if (typeof config === 'object') %7B%0A    nconf.add('supplied', %7B%0A      type: 'literal',%0A      store: config,%0A    %7D);%0A  %7D%0A%0A  nconf%0A    .use('memory')%0A    .env('__')%0A    .file(path.join(__dirname, 'default.json'));%0A%0A  
 const db = r
@@ -592,16 +592,18 @@
 se')();%0A
+  
 const re
@@ -632,24 +632,26 @@
 ealtime');%0A%0A
+  
 const primus
@@ -662,16 +662,18 @@
 ons = %7B%0A
+  
   transf
@@ -696,12 +696,16 @@
 o',%0A
+  
 %7D;%0A%0A
+  
 cons
@@ -746,16 +746,18 @@
 tions);%0A
+  
 realtime
@@ -768,16 +768,18 @@
 t(io);%0A%0A
+  
 const de
@@ -826,16 +826,18 @@
 -jwt');%0A
+  
 const co
@@ -876,16 +876,18 @@
 ers');%0A%0A
+  
 app.use(
@@ -926,24 +926,26 @@
 : true %7D));%0A
+  
 app.use(body
@@ -960,16 +960,18 @@
 son());%0A
+  
 app.use(
@@ -982,16 +982,18 @@
 deJwt);%0A
+  
 app.use(
@@ -1011,26 +1011,8 @@
 );%0A%0A
-function init() %7B%0A
   _.

refactor to use new config pattern