/
common.clj
51 lines (45 loc) · 1.34 KB
/
common.clj
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
(ns shadow.cljs.devtools.server.web.common
(:require [shadow.server.assets :as assets]
[hiccup.page :refer (html5)]
[hiccup.core :refer (html)]
[clojure.java.io :as io]
[shadow.core-ext :as core-ext]))
(defn not-found
([req]
(not-found req "Not found."))
([req msg]
{:status 404
:headers {"content-type" "text/plain"}
:body msg}))
(defn unacceptable [_]
{:status 406 ;; not-acceptable
:headers {"Content-Type" "text/plain"}
:body "websocket required"})
(defn edn [req data]
{:status 200
:header {"content-type" "application/edn"}
:body (core-ext/safe-pr-str data)})
(defn page-boilerplate
[req ^String content]
{:status 200
:headers {"content-type" "text/html; charset=utf-8"}
:body
(html5
{:lang "en"}
[:head
;; lol preload for local dev
[:link {:as "script" :href "/js/ui.js" :rel "preload"}]
[:title "shadow-cljs"]
[:style "body { font-size: 12px; font-family: Menlo, monospace; padding: 10px; margin: 0;"]]
[:body
content
[:script {:src "/js/ui.js" :defer true}]
])})
(defn nav []
(html
[:div
[:a {:href "/explorer"} "home"]]))
(defn transit [{:keys [transit-str] :as req} obj]
{:status 200
:headers {"content-type" "application/transit+json; charset=utf-8"}
:body (transit-str obj)})