 # Doesn't seem to do much.
 mongoose.connection.on 'error', (err) ->
   console.warn "MONGOOSE CONNECTION ERROR #{err}"
+
+if process.env.NODETIME_KEY
+  nodetime.profile
+    accountKey: process.env.NODETIME_KEY
+    appName: process.env.CU_NODETIME_APP
+
+# TODO: move into npm module
+nodetimeLog = (req, res, next) ->
+  matched = _.find app.routes[req.method.toLowerCase()], (route) ->
+    route.regexp.test req.url
+  if matched.path isnt '*'
+    res.nodetimePromise = nodetime.time 'Custard request ', matched.path, req.url
+    oldSend = res.send
+    res.send = (args... ) ->
+      res.nodetimePromise.end()
+      oldSend.apply res, args
+  return next()
 
 assets.jsCompilers.eco =
   match: /\.eco$/

  if not process.env.NODE_ENV
    # Set the public folder as static assets
    app.use express.static(process.cwd() + '/shared')

passport.use 'local', new LocalStrategy(verify)


existsSync = fs.existsSync || path.existsSync
crypto = require 'crypto'
child_process = require 'child_process'
util = require 'util'

_ = require 'underscore'
express = require 'express'
