about summary refs log blame commit diff stats
path: root/bb/web/htmx.clj
blob: c534dd159a01abb750814165cf42ae460e0914a5 (plain) (tree)
1
2
3
4
5
6
7
8
9



                                                                             


                                          

                              

               





                               
                                 


                     












                                            




                                      




                                                                               








                                                                                 
#!/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)))