SivanMehta / treedoff

Exploring tradeoffs with a tree
0 stars 0 forks source link

Outline Server Startup #37

Closed SivanMehta closed 7 years ago

SivanMehta commented 7 years ago

The file server/index.js was getting very bulky, and it was hard to track what was going on when. Now, we can look at server/index.js and see a very explicit outline of what part of the service is being initialized and when, rather than the monolithic block of code that was there before.

const initializers = [
  // logger
  './initializers/logger',

  // parsing HTTP request
  './initializers/body-parser',

  // connect to database and load models
  './models',

  // passport usage
  './passport',

  // authorization middleware and routes
  './auth',

  // api definitions
  './api',

  // Serve static assets
  './initializers/static-assets.js'
]

These are then all ran sequentially, using async.waterfall to keep track and make sure every necessary module is initialized successfully.