#!/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 "" (h/html [:head [:meta {:charset "UTF-8"}] [:title "Babashka go brrr"]] [:body [:section.main [:header.header [:h1 "Hullo, Frodo!"]]]]))) (defn about [] (list "" (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)))