(defn handler [{:keys [uri] :as request}]
(or (case uri
"/"
{:status 200
:headers {"Content-Type" "text/html"}
:body (page uri {:static? false})}
"/eval"
{:status 200
:headers {"Content-Type" "text/plain"}
:body (->> request
:body
.bytes
slurp
edn/read-string
(#(es/code->results % {:disable-security? true}))
(mapv u/form->serializable)
pr-str)}
"/dynadoc-export.zip"
{:status 200
:headers {"Content-Type" "application/zip"}
:body (export (:params request))}
"/watch"
(watch/watch-request request)
nil)
(let [[type ns-sym var-sym] (u/parse-uri uri)]
(when (contains? #{:clj :cljs} type)
{:status 200
:headers {"Content-Type" "text/html"}
:body (page uri {:static? false :type type :ns-sym ns-sym :var-sym var-sym})}))
(not-found "Page not found")))