   app.use express.static(path.resolve __dirname, '../../public')
 
   # Error handler
+  if SENTRY_PRIVATE_DSN
+    app.use RavenServer.errorHandler()
+
   require('../../components/error/server') app

  app.use bucketAssets()
  setupAuth app
  app.use locals

  if SENTRY_PRIVATE_DSN
    app.use RavenServer.errorHandler()

  app.use helpers
  app.use ua
  app.use sameOrigin


module.exports = (app) ->

  # Configure Sentry
  if SENTRY_PRIVATE_DSN
    RavenServer.config(SENTRY_PRIVATE_DSN).install()
    app.use RavenServer.requestHandler()

  # Override Backbone to use server-side sync
  Backbone.sync = require 'backbone-super-sync'

  # Route to ping for system up
  app.get '/system/up', (req, res) ->
    res.send 200, { nodejs: true }

  # Mount generic middleware & run setup modules
  if 'production' is NODE_ENV or 'staging' is NODE_ENV
