-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
node.cljs
31 lines (28 loc) · 989 Bytes
/
node.cljs
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
(ns portal.client.node
(:require
[clojure.string :as str]
[portal.client.common :refer (->submit)]))
(defn fetch [url options]
(let [https? (str/starts-with? url "https")
http (js/require (str "http" (when https? "s")))]
(js/Promise.
(fn [resolve reject]
(let [req (.request
http
url
(clj->js options)
(fn [^js res]
(let [body (atom "")]
(.on res "data" #(swap! body str %))
(.on res "error" reject)
(.on res "end" #(resolve
{:status (.-statusCode res)
:body @body})))))]
(.write req (:body options))
(.end req))))))
(def submit (->submit fetch))
(comment
(submit {:runtime :node :value "hello node"})
(add-tap submit)
(tap> {:runtime :node :value "hello node-tap"})
(add-tap submit))