This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-02
Channels
- # beginners (72)
- # boot (68)
- # cider (51)
- # clara (20)
- # cljs-dev (44)
- # cljsrn (7)
- # clojure (168)
- # clojure-brasil (1)
- # clojure-dev (48)
- # clojure-greece (2)
- # clojure-nl (29)
- # clojure-russia (4)
- # clojure-spec (19)
- # clojure-uk (28)
- # clojurescript (2)
- # cursive (9)
- # datascript (1)
- # datomic (105)
- # dirac (1)
- # docker (2)
- # duct (11)
- # emacs (19)
- # events (1)
- # figwheel (1)
- # fulcro (23)
- # garden (4)
- # graphql (5)
- # hoplon (46)
- # jobs (5)
- # juxt (13)
- # leiningen (6)
- # lumo (12)
- # off-topic (29)
- # parinfer (5)
- # re-frame (7)
- # reagent (6)
- # ring (2)
- # sql (5)
- # yada (6)
Hi, I am new to yada and having trouble understanding how to use the interceptor-chain from the docs but the docs in that area seem incomplete/incorrect. My service at this point has been just using yada/resource to create resources so I assume it is somehow getting the default interceptor chain when interpreted by Yada. To modify the chain the only way I can see to do it is to wrap the resources in yada/handler to create a chain and then modify it. Is this correct?
(yada.handler/append-interceptor
(yada/handler
(yada/resource {:methods {:get {:consumes "text/plain"
:produces "text/plain"
:response (fn [ctx] "hello")}}}))
yada.interceptors/return
identity)
@sofra not sure if this is the 'official' way to do it, but I tend to walk my route tree when I'm building the routes and assoc the default interceptors, then modify them there
(defn update-resources [routes f & args]
(walk/postwalk
(fn [x]
(if (instance? Resource x)
(resource (apply f x args))
x))
routes))
(-> ["" [(index/index-routes postgres config)]]
(update-resources
(fn add-default-interceptors [resource]
(cond-> resource
(not (contains? resource :interceptor-chain)) (assoc :interceptor-chain yada/default-interceptor-chain)
(not (contains? resource :error-interceptor-chain)) (assoc :error-interceptor-chain yada/default-error-interceptor-chain))))
...
(update-resources append-error-interceptor i/logging
(error-reporters/make-report-error-interceptor reporter))
(update-resources yada.handler/append-interceptor sec/security-headers
private-cache-control-headers)
(update-resources
;; Add custom 401 page to tell people to login.
(fn [resource]
(if (some? (yada.util/get* (:responses resource) 401))
resource
(assoc-in resource [:responses 401] custom-401)))))
This is an area of Yada that I think could be made better
@danielcompton interesting, thanks for that