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

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

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

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

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

#
# Initialize our libraries

module.exports.start = (options, callback) ->
  port = 3000
  port = options.port if (options && options.port)
  server.listen port, undefined, (callback) ->
    if (server.settings.env != 'test')
      console.log("server listening on port #{port} in #{server.settings.env} mode")


stop = module.exports.stop = (exitCode = 0) ->
