index.js
function (callback) {
    var APIController = require('./controllers/api'),
      DefaultController = require('./controllers/index'),
      PackController = require('./controllers/pack'),
      CardController = require('./controllers/card'),
      WebHookController = require('./controllers/webhook'),
      ProxyController = require('./controllers/proxy'),
      JsonParser = BodyParser.json({strict: false});
    
    // Disable caching middleware.  
    var nocache = function (req, res, next) {
      res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
      res.header('Expires', '-1');
      res.header('Pragma', 'no-cache');
      next();
    };
    
    // Setup routes late to give implementers routes higher priority and allow middleware as well.
    App.get('/api/count', nocache, APIController.count);
    App.get('/api/cards', nocache, APIController.cards);
    App.get('/api/card', nocache, APIController.card);
    
    App.post('/api/card/state/save', APIController.saveState);
    App.post('/api/card/state/clear', APIController.clearState);
    App.post('/api/card/analytics', APIController.recordAnalyticEvents);

    // Proxy
    App.post('/proxy/:pack/:card', ProxyController.post);

    // Web Hooks
    App.post('/webhook/:pack/:card', WebHookController.process);

    // Card Routes
    App.post('/:pack/:card', JsonParser, CardController.post);
    App.get('/:pack/:card', CardController.get);
    
    App.get('/:pack', PackController);
    App.get('/', DefaultController);

    var exit = function () {
      HashDo.db.disconnect(function () {
        process.exit(0);
      });
    };
    
    // Gracefully disconnect from the database on expected exit.
    process.on('SIGINT', exit);
    process.on('SIGTERM', exit);
    
    // Global error handler (always exit for programmatic errors).
    process.on('uncaughtException', function (err) {
      console.error('FATAL: ', err.message);
      console.error(err.stack);
      process.exit(1);
    });
    
    // Connect to the database and start server on successful connection.
    HashDo.db.connect(function (err) {
      if (err) {
        console.error('FATAL: Could not connect to database.', err);
        process.exit(1);
      }
      else {
        console.log('WEB: Starting web server on port %d...', process.env.PORT);
        
        App.listen(process.env.PORT, function () {
          console.log();
          console.log('Let\'s #Do');
          
          callback && callback();
        });
      }
    });
  }
function (callback) {
    var APIController = require('./controllers/api'),
      DefaultController = require('./controllers/index'),
      PackController = require('./controllers/pack'),
      CardController = require('./controllers/card'),
      WebHookController = require('./controllers/webhook'),
      ProxyController = require('./controllers/proxy'),
      JsonParser = BodyParser.json({strict: false});
    
    // Disable caching middleware.  
    var nocache = function (req, res, next) {
      res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
      res.header('Expires', '-1');
      res.header('Pragma', 'no-cache');
      next();
    };
    
    // Setup routes late to give implementers routes higher priority and allow middleware as well.
    App.get('/api/count', nocache, APIController.count);
    App.get('/api/cards', nocache, APIController.cards);
    App.get('/api/card', nocache, APIController.card);
    
    App.post('/api/card/state/save', APIController.saveState);
    App.post('/api/card/state/clear', APIController.clearState);
    App.post('/api/card/analytics', APIController.recordAnalyticEvents);

    // Proxy
    App.post('/proxy/:pack/:card', ProxyController.post);

    // Web Hooks
    App.post('/webhook/:pack/:card', WebHookController.process);

    // Card Routes
    App.post('/:pack/:card', JsonParser, CardController.post);
    App.get('/:pack/:card', CardController.get);
    
    App.get('/:pack', PackController);
    App.get('/', DefaultController);

    var exit = function () {
      HashDo.db.disconnect(function () {
        process.exit(0);
      });
    };
    
    // Gracefully disconnect from the database on expected exit.
    process.on('SIGINT', exit);
    process.on('SIGTERM', exit);
    
    // Global error handler (always exit for programmatic errors).
    process.on('uncaughtException', function (err) {
      console.error('FATAL: ', err.message);
      console.error(err.stack);
      process.exit(1);
    });
    
    // Connect to the database and start server on successful connection.
    HashDo.db.connect(function (err) {
      if (err) {
        console.error('FATAL: Could not connect to database.', err);
        process.exit(1);
      }
      else {
        console.log('WEB: Starting web server on port %d...', process.env.PORT);
        
        App.listen(process.env.PORT, function () {
          console.log();
          console.log('Let\'s #Do');
          
          callback && callback();
        });
      }
    });
  }
function ( callback ) { var APIController = require ( './controllers/api' ) , DefaultController = require ( './controllers/index' ) , PackController = require ( './controllers/pack' ) , CardController = require ( './controllers/card' ) , WebHookController = require ( './controllers/webhook' ) , ProxyController = require ( './controllers/proxy' ) , JsonParser = BodyParser . json ( { strict : false } ) ; // Disable caching middleware.   var nocache = function ( req , res , next ) { res . header ( 'Cache-Control' , 'private, no-cache, no-store, must-revalidate' ) ; res . header ( 'Expires' , '-1' ) ; res . header ( 'Pragma' , 'no-cache' ) ; next ( ) ; } ; // Setup routes late to give implementers routes higher priority and allow middleware as well. App . get ( '/api/count' , nocache , APIController . count ) ; App . get ( '/api/cards' , nocache , APIController . cards ) ; App . get ( '/api/card' , nocache , APIController . card ) ; App . post ( '/api/card/state/save' , APIController . saveState ) ; App . post ( '/api/card/state/clear' , APIController . clearState ) ; App . post ( '/api/card/analytics' , APIController . recordAnalyticEvents ) ; // Proxy App . post ( '/proxy/:pack/:card' , ProxyController . post ) ; // Web Hooks App . post ( '/webhook/:pack/:card' , WebHookController . process ) ; // Card Routes App . post ( '/:pack/:card' , JsonParser , CardController . post ) ; App . get ( '/:pack/:card' , CardController . get ) ; App . get ( '/:pack' , PackController ) ; App . get ( '/' , DefaultController ) ; var exit = function ( ) { HashDo . db . disconnect ( function ( ) { process . exit ( 0 ) ; } ) ; } ; // Gracefully disconnect from the database on expected exit. process . on ( 'SIGINT' , exit ) ; process . on ( 'SIGTERM' , exit ) ; // Global error handler (always exit for programmatic errors). process . on ( 'uncaughtException' , function ( err ) { console . error ( 'FATAL: ' , err . message ) ; console . error ( err . stack ) ; process . exit ( 1 ) ; } ) ; // Connect to the database and start server on successful connection. HashDo . db . connect ( function ( err ) { if ( err ) { console . error ( 'FATAL: Could not connect to database.' , err ) ; process . exit ( 1 ) ; } else { console . log ( 'WEB: Starting web server on port %d...' , process . env . PORT ) ; App . listen ( process . env . PORT , function ( ) { console . log ( ) ; console . log ( 'Let\'s #Do' ) ; callback && callback ( ) ; } ) ; } } ) ; }
Sets up internal routes and starts the web server,
Ensure you call the init function before starting the web server.

@method start
@async

@param {Function}  [callback]  Optional callback to be nitified when the server has started and ready for requests.
Sets up internal routes and starts the web server Ensure you call the init function before starting the web server .