                          (let [db (db/save-fiddle conn
                                                   (util/fiddle (:cljs fiddle)
                                                                (:html fiddle)
-                                                               (:css  fiddle)))] 
+                                                               (:css  fiddle)))]
                            {:status :save-success
                             :date (subs (->> db d/basis-t d/t->tx (d/entity db) :db/txInstant pr-str)
                                         7 36)

         (assoc (res/redirect (if-let [fiddle (:fiddle session)]
                                (str "/fiddle/" fiddle)
                                "/"))
           :session (merge session {:token token 
                                    :username username})))))

   (GET "/logout"
     []
     (assoc (res/redirect "/") :session nil))
   
   (context "/compiler" [] (closure/compile-routes conn))
   (context "/deps" [] (closure/deps-routes conn))
   
   (route/resources "/")
   (route/not-found "Not Found")))

(defn app [conn store]
  (handler/site (app-routes conn) 
                {:session {:store store}}))

(defn -main []
  (let [port (Integer/parseInt (or (env "PORT") "8080"))
        store (cookie/cookie-store {:key (env :session-secret)})
        db-uri (env :datomic-uri)
        conn (d/connect db-uri)]
    (jetty/run-jetty (-> (app conn store)
                         wrap-edn-params
                         wrap-stacktrace) 
                     {:port port :join? false})))

;; (.stop server)

    (catch Exception e
      [:exception (.getMessage e)])))

(defn as-of*
  "Get the db as of date or latest db if date is nil"
  [conn date]
  (let [db (d/db conn)]
