 mw = require('./middleware')
 
 # Module variables
-app = express()
+server = express()
 isShuttingDown = false
 FATAL_EXIT_CODE = 13
 

#
module.exports.init = (options, callback) ->
  initMiddleware()
  router.buildRoutes(app, options.routes)
  initLibs(callback)

#

# Initialize middleware stack
#
initMiddleware = ->
  server.configure ->
    server.set('views', rendr.entryPath + '/views')
    server.set('view engine', 'coffee')
    server.engine('coffee', require('./view_engine'))
    server.use(express.logger())
    server.use(express.compress())
    server.use(express.bodyParser())
    server.use(express.cookieParser())
    server.use(express.methodOverride())
    server.use(express.static(rendr.entryPath + '/../public'))
    server.use(mw.startRequest())
    server.use(mw.createAppInstance())
    # server.use(mw.getAccessToken())
    # server.use(mw.userConfig())
    server.use(server.router)
    # server.use(mw.logResponse())
    server.use('/api', apiProxy)

  server.configure 'test', ->
    server.use(express.errorHandler({ dumpExceptions: true, showStack: true }))

  server.configure 'development', ->
    server.use(express.errorHandler({ dumpExceptions: true, showStack: true }))

  server.configure 'production', ->
    server.use(express.errorHandler())

#
# Initialize our libraries
