about summary refs log tree commit diff stats
path: root/bb/web
diff options
context:
space:
mode:
authorelioat <hi@eli.li>2023-12-08 22:33:59 -0500
committerelioat <hi@eli.li>2023-12-08 22:33:59 -0500
commit7c6fd4b424d5ec1701a5a42f4e305bb2e4492145 (patch)
tree4ae7a87d9ce5e9d25c66434f4d44accc0332f06a /bb/web
parentf88282a3590b37292d447dc6ef4532e84dad46ea (diff)
downloaddecember-2023-7c6fd4b424d5ec1701a5a42f4e305bb2e4492145.tar.gz
*
Diffstat (limited to 'bb/web')
-rw-r--r--bb/web/htmx.clj30
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