This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-12
Channels
- # aleph (1)
- # aws (2)
- # babashka (44)
- # beginners (178)
- # biff (12)
- # calva (22)
- # chlorine-clover (60)
- # cider (1)
- # clj-kondo (9)
- # cljdoc (6)
- # cljs-dev (37)
- # cljss (2)
- # clojure (43)
- # clojure-europe (3)
- # clojure-finland (23)
- # clojure-italy (1)
- # clojure-nl (4)
- # clojure-norway (3)
- # clojure-spec (56)
- # clojure-uk (148)
- # clojuredesign-podcast (1)
- # clojurescript (11)
- # conjure (5)
- # core-async (22)
- # cursive (9)
- # datascript (5)
- # datomic (4)
- # duct (8)
- # emotion-cljs (2)
- # figwheel-main (15)
- # fulcro (53)
- # graalvm (68)
- # helix (2)
- # jackdaw (1)
- # kaocha (9)
- # lambdaisland (1)
- # malli (10)
- # meander (2)
- # news-and-articles (1)
- # observability (12)
- # off-topic (17)
- # pathom (1)
- # pedestal (25)
- # practicalli (1)
- # protojure (4)
- # re-frame (2)
- # reagent (57)
- # reitit (1)
- # releases (2)
- # shadow-cljs (69)
- # specter (6)
- # tools-deps (10)
- # vim (16)
- # vscode (4)
- # yada (3)
I'm thinking it makes sense to have my db pool as context accessible from an http request
@emccue if you mean having an interceptor execute prior to any handler irrespective of route then you can create a common-interceptors coll and add it there. The buddy-auth sample does this to ensure the authentication interceptors are executed for each route (https://github.com/pedestal/pedestal/blob/master/samples/buddy-auth/src/buddy_auth/service.clj#L74-L80)
How do I know which websocket session sent the message here? https://github.com/pedestal/pedestal/blob/master/samples/jetty-web-sockets/src/jetty_web_sockets/service.clj#L58
this was the sample listener
(defn ws-listener
[_request _response ws-map]
(proxy [WebSocketAdapter] []
(onWebSocketConnect [^Session ws-session]
(proxy-super onWebSocketConnect ws-session)
(when-let [f (:on-connect ws-map)]
(f ws-session)))
(onWebSocketClose [status-code reason]
(when-let [f (:on-close ws-map)]
(f (.getSession this) status-code reason)))
(onWebSocketError [^Throwable e]
(when-let [f (:on-error ws-map)]
(f (.getSession this) e)))
(onWebSocketText [^String message]
(when-let [f (:on-text ws-map)]
(f (.getSession this) message)))
(onWebSocketBinary [^bytes payload offset length]
(when-let [f (:on-binary ws-map)]
(f (.getSession this) payload offset length)))))
;; in your service map:
::http/container-options {:context-configurator #(ws/add-ws-endpoints % ws-paths {:listener-fn ws-listener})}
no prob, I've been meaning to try this out too. would be great if you don't mind posting your working service setup when you have one
@isak I hacked together the above sample, inspired by https://github.com/sunng87/ring-jetty9-adapter/blob/40aab6d0b91a7d7b63b9bf39e62e1f9801a02d3e/src/ring/adapter/jetty9/websocket.clj#L122 Hit me up if you cannot get it to work.
cool @hindol.adhya @danvingo, I just got it to work. Btw I noticed it is pretty hard to get a good reloading experience with the socket handlers, but here is one thing that works:
Yeah Java code is calling into this code. Reloading should work with the right indirection in place.
i'm writing a 'not found' interceptor to send all requests that were not fulfilled to another backend server and passes through its response to the output. all works, except for requests w/ a really large body, the body gets cut off in the output. it's complete in the request though. when i println the request i can see the entire body. but the output is truncated. i'm using immutant though jetty does the same. what could be causing this?
(defn send-request
[request]
(println request)
(try
(let [params {:url (str (config/env :neo-api-url) (:uri request))
:body (:body request)
:method (:request-method request)
:socket-timeout 10000 ;; in milliseconds
:connection-timeout 1000
:headers (merge (:headers request)
{:authorization (str "Bearer " (config/env :neo-api-token))
:accept "application/vnd.ucf.v1+json"})}
response (client/request params)]
(println response)
response)
(catch Exception e
(timbre/warn "Could not reach API server" e))))
(def passthrough
{:name ::passthrough
:leave (fn [context]
(let [request (:request context)]
(assoc context :response (send-request request))))})
i think the issue is the headers coming back esp content-length. i updated the code to only take the body and put it in a new response and it's working now:
(assoc context :response (response/response (:body (send-request request))))))})
is there an interceptor or other way to define params using plumatic schema like compojure-api/reitit or some other way of declarative parameter handling? other than using the reitit router in pedestal that is
Hi, have you looked at https://github.com/oliyh/pedestal-api ?