         [hiccup.form]
         [hiccup.page]
         [hiccup.element]
-        [ring.util.response])
+        [ring.util.response]
+        [clojure.data],
+        [clojure.java.io])
   (:require [compojure.handler :as handler]
             [compojure.route :as route]
             [monger.core :as mg]
             [monger.collection :as mc]
             [monger.query :as mq]
-            [monger.joda-time])
+            [monger.joda-time]
+            [clojure.data.json :as json])
   (:import [org.joda.time DateTime DateTimeZone]
            [org.bson.types ObjectId]))
 
-(def db-uri "mongodb://drutten:gena@localhost:27017/notes")
-
 (DateTimeZone/setDefault DateTimeZone/UTC)
 
-(mg/connect-via-uri! db-uri)
+(def mongo-host "localhost")
+(def mongo-port "27017")
+(def mongo-username "test")
+(def mongo-password "test")
+(def environment-file "/home/dotcloud/environment.json")
+
+(if (.exists (as-file environment-file))
+(
+  (def environment (json/read (reader (file environment-file))))
+  (def mongo-host (val (find environment "DOTCLOUD_MONGO_MONGODB_HOST")))
+  (def mongo-port (val (find environment "DOTCLOUD_MONGO_MONGODB_PORT")))))
+
+(mg/connect-via-uri! (str "mongodb://" mongo-username ":" mongo-password "@" mongo-host ":" mongo-port "/notes"))
 
 (defn save-note! [note]
   (mc/insert "notes" note))

  (html
    (html5
      [:head [:title "Notes"]
       (include-css "/css/bootstrap.min.css")
       (include-css "/css/notes.css")
       (include-css "/css/jquery-ui-1.9.2.custom.min.css")]

      [:body [:div.navbar.navbar-fixed-top [:div.navbar-inner [:div.container (link-to {:class "brand"} "#" "Notes!")]]]

       [:header
        [:div.container (image {:id "note"} "/img/note.png")
         [:div#header-txt [:h1 "Notes!"]
         [:p.lead [:small " Create and read awesome notes, right here!"]]]]]

       [:div.container
        [:div.row-fluid
         [:div.span4 [:div#add-note.affix-top {:data-spy "affix", :data-offset-top "215"}
                                                    (form-to [:post "/"]
                                                      [:fieldset [:label "Heading"]
                                                       (text-field :heading )
                                                       [:label "Note"]

  (route/not-found "Not Found"))

(def app
  (handler/site app-routes))
