   router.buildRoutes(server)
   initLibs(callback)
 
+exports.setDataAdapter = (dataAdapter) ->
+  exports.dataAdapter = dataAdapter
+
 # Use default, stubbed dataAdapter.
 # To be overridden by application.
-module.exports.dataAdapter = dataAdapter
+exports.setDataAdapter(dataAdapter)
 
 #
 # options

    runUserMiddleware()

    server.use(server.router)
    server.use('/api', stubApiProxy)

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

closeLibs = (callback) ->
  callback()


# middleware handler for intercepting api routes
apiProxy = ->
  (req, res, next) ->
    exports.dataAdapter.makeRequest req, (err, response, body) ->
      return next(err) if err
      # Pass through statusCode, but not if it's an i.e. 304.
      if response.statusCode? && _.include(['5', '4'], response.statusCode.toString()[0])
        res.status(response.statusCode)
      res.json(body)

