 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-fs = require("fs")
-express = require("express")
-routes = require("./routes")
+ 
+fs = require "fs"
+os = require "os"
+path = require "path"
+
+_ = require "underscore"
+express = require "express"
+Databank = require("databank").Databank
+
+routes = require "./routes"
 localURL = require("./url").localURL
-config = require("./config")
-os = require("os")
-Databank = require("databank").Databank
-globals = require("./globals")
+globals = require "./globals"
 Hub = require("./hub").Hub
 Feed = require("./feed").Feed
-server = config.server or os.hostname()
+
+CONFIG_FILE = "/etc/ofirehose.json"
+
+defaults =
+  key: null
+  cert: null
+  server: os.hostname()
+  driver: "memory"
+  params: {}
+  address: null
+  
+if fs.existsSync(CONFIG_FILE)
+  try
+    config = JSON.parse(fs.readFileSync(CONFIG_FILE))
+  catch err
+    console.error err
+    process.exit 1
+else
+  config = {}
+
+config = _.defaults config, defaults
+  
+server = config.server
 address = config.address or server
 useHTTPS = (if (config.key) then true else false)
-app = undefined
-bounce = undefined
+
 localURL.server = server
 localURL.protocol = (if (useHTTPS) then "https" else "http")
+
 if useHTTPS
   app = express.createServer(
     key: fs.readFileSync(config.key)


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


# Routes
app.get "/", routes.index

      bounce.listen 80, address
    else
      app.listen 80, address
