about summary refs log tree commit diff stats
path: root/bb/web/htmx.clj
blob: c534dd159a01abb750814165cf42ae460e0914a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bb

(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]
         '[hiccup.core :as h])

(def port 3000)

(defn index []
  (list
   "<!DOCTYPE html>"
   (h/html
    [:head
     [:meta {:charset "UTF-8"}]
     [:title "Babashka go brrr"]]
    [:body
     [:section.main
      [:header.header
       [:h1 "Hullo, Frodo!"]]]])))

(defn about []
  (list
   "<!DOCTYPE html>"
   (h/html
    [:head
     [:meta {:charset "UTF-8"}]
     [:title "Aboot"]]
    [:body
     [:section.main
      [:header.header
       [:h1 "Don't touch them Frodo!"]]]])))

(def routes [{:path     "/"
              :method   :get
              :response {:body (index)
                         :status 200
                         :headers {"Content-Type" "text/html; charset=utf-8"}}}
             {:path     "/about"
              :method   :get
              :response {:body (about)
                         :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)))