Use supplied config option when loading config

Oops
Move middleware code to middleware.rb
Use constants for default option values
Move db, config loading to methods
Fetch db to supplied path, with a fallback default