Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Core Bootstrap

cliftonc edited this page Aug 24, 2011 · 7 revisions

Bootstrap

The bootstrap (or initial load of Calipso) happens across a sequence of stages, and is driven by 5 core files (in loosely the following order):

  • app.js
  • conf/configuration.js
  • lib/calipso.js
  • lib/Theme.js
  • lib/Router.js

app.js

To launch calipso directly, you simply run the command:

node app

From the project directory. What this does is launch the basic server in the following pseudo-code flow:

  • Require dependent libraries, initialise local variables for later use.
  • Bootstrap the application, returning a reference to the Express app.
  • Start the server listening on the supplied port (3000 default).

Clearly, the most important step here is the 'bootstrap the application', this is handled by two functions defined within app.js.

boot

This is an exported function (to enable it to be called by the bin/calipso script and the app-cluster scripts), that has the responsibility for:

  • Creating the express application (referred to by app)
  • Loading the configuration (via conf/configuration.js) - see Configuration
  • Using the configuration to then boot Calipso (via the bootApplication function below).

bootApplication

This function takes the express application, with its configuration, and attaches all of the required connect middleware, and custom middleware, required for Calipso to work.

The following express / connect middleware:

  • methodOverride
  • cookieParser
  • responseTime
  • session (Using the connect-mongodb session storage)
  • stylusMiddleware (linked to the configured theme, tagged 'themeStylus' for later reference)
  • static (for the theme static folder - tagged 'themeStatic' for later reference)
  • static (for the media folder)
  • connect-form

The following custom Calipso middleware:

  • translation (via i18n/translate.js) - translate
  • calipso (via lib/calipso.js) - calipsoRouter

The end result being that we have a fully configured Express application, with the appropriate middleware configured. It passes this back in the callback to indicate that the boot is complete. The app object is then always accessible via the calipso.app shortcut in any module.