-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.clj
34 lines (29 loc) · 923 Bytes
/
interface.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
(ns cljs-csvc.http.interface
(:require [compojure.handler :as handler]
[cljs-csvc.compiler :as comp]
[clojure.string :as str]))
(defn str-to-bool [str]
(condp = (str/upper-case str)
"TRUE" true
false))
(defn parse-params [params]
(let [{:keys [cs-code optimizations pretty-print]
:or {optimizations "advanced"
pretty-print "true"}} params]
[cs-code (keyword optimizations) (str-to-bool pretty-print)]))
(defn call-build [[code opt pp]]
(try
[200 (comp/build code {:optimizations opt, :pretty-print pp})]
(catch Exception e
[400 (str "caught exception: " (.getMessage e))])))
(defn format-response
"Need m0ar functionality"
[[status body]]
{:status status
:headers {"Content-Type" "text/plain"}
:body body})
(defn handle-compile [params]
(->> params
parse-params
call-build
format-response))