   # that is passed in and then does its
   # best to supply sane defaults for any arguments that are missing.
   argv = defargs(argv)
+  errorHandler = (req, res, next) ->
+    fired = false
+    res.e = (error, status) ->
+      if !fired
+        fired = true
+        res.statusCode = status or 500
+        res.end 'Server ' + error
+        console.log("Res sent: " + res.statusCode + ' ' + error) if argv.debug
+      else
+        console.log "Allready fired " + error
+    next()
+
   app.startOpts = do ->
     options = {}
     for own k, v of argv

  )

  app.get ////plugins/(factory/)?factory.js///, (req, res) ->
    onerr = errorHandler(res)
    cb = (e, catalog) ->
      if e then return onerr(e)
      res.write('window.catalog = ' + JSON.stringify(catalog) + ';')
      fs.createReadStream(argv.c + '/plugins/meta-factory.js').pipe(res)

    glob argv.c + '/**/factory.json', (e, files) ->
      if e then return cb(e)
      files = files.map (file) ->
        return fs.createReadStream(file).on('error', onerr).pipe(
          JSONStream.parse([false]).on 'root', (el) ->
            @.emit 'data', el
        )

      es.concat.apply(null, files)
        .on('error', onerr)
        .pipe(es.writeArray(cb))

  ###### Json Routes ######

        else
          done(null, false)
      else
        setOwner id, (e) ->
          if e then return done(e)
          done(null, {id})
    )
  )))
