diff options
Diffstat (limited to 'bb')
-rw-r--r-- | bb/web/htmx.clj | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/bb/web/htmx.clj b/bb/web/htmx.clj index 772da25..3294e2d 100644 --- a/bb/web/htmx.clj +++ b/bb/web/htmx.clj @@ -2,15 +2,35 @@ (require '[babashka.deps :as deps]) (deps/add-deps '{:deps {org.clojars.askonomm/ruuter {:mvn/version "1.3.2"}}}) - (require '[org.httpkit.server :as srv] '[clojure.java.browse :as browse] '[ruuter.core :as ruuter] - '[clojure.pprint :refer [cl-format]] - '[clojure.string :as str] '[hiccup.core :as h]) -(import '[java.net URLDecoder]) - (def port 3000) +(defn index [] + (list + "<!DOCTYPE html>" + (h/html + [:head + [:meta {:charset "UTF-8"}] + [:title "Babashka"]] + [:body + [:section.main + [:header.header + [:h1 "hullo, frodo!"]]]]))) + +(def routes [{:path "/" + :method :get + :response {:body (index) + :status 200 + :headers {"Content-Type" "text/html; charset=utf-8"}}}]) + +;; Server +(when (= *file* (System/getProperty "babashka.file")) + (let [url (str "http://localhost:" port "/")] + (srv/run-server #(ruuter/route routes %) {:port port}) + (println "serving" url) + (browse/browse-url url) + @(promise))) \ No newline at end of file |