This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-26
Channels
- # announcements (1)
- # atom-editor (7)
- # babashka (9)
- # beginners (46)
- # cider (1)
- # circleci (2)
- # clj-on-windows (1)
- # cljdoc (5)
- # cljsrn (2)
- # clojure (25)
- # clojure-austin (8)
- # clojure-brasil (4)
- # clojure-europe (52)
- # clojure-nl (1)
- # clojure-norway (162)
- # clojure-uk (2)
- # cursive (3)
- # datalevin (134)
- # datomic (16)
- # defnpodcast (8)
- # graphql (9)
- # honeysql (5)
- # hoplon (26)
- # hyperfiddle (18)
- # introduce-yourself (1)
- # lsp (4)
- # malli (19)
- # nbb (16)
- # nrepl (1)
- # practicalli (3)
- # releases (3)
- # shadow-cljs (36)
- # tools-deps (7)
- # vim (2)
- # xtdb (9)
Hey all! I've got a question: How can I add an unauthenticated route to the service map generated by lacinia.pedestal2
?
I'm trying to add a /health
endpoint to the service-map generated by lacinia.pedestal2/default-service
. I've basically got it "working", but the issue I'm running into is with the authentication interceptor I wrote -- I'd like all the Lacinia related endpoints to be authenticated against, but I'd like /health
to be open. Code in ๐งต
The code looks something like this (this is slightly simplified from what I'm actually doing, but the core logic is here):
(let [health-endpoint #{["/health" :get (fn health [_] {:status 200 :headers {} :body "true"}) :route-name ::health]}]
(-> schema/load-schema
(lp/default-service {:port 8000 :host "localhost"})
(update ::http/routes #(into % health-endpoint))
http/default-interceptors
(update ::http/interceptors
into
[http/json-body
(auth/jwt-authentication-interceptor)])))
I'm fairly new to lacinia and pedestal, so I'm probably missing something obvious here...
The jwt-authentication-interceptor
looks something like this (again, slightly simplified...):
(defn jwt-authentication-interceptor
[]
(interceptor/before
::jwt-authentication
(fn [ctx]
(authenticate ctx))))
This is a case where you just don't use the default-service
function; as documented, it's initial scaffolding but you will want to unpack it into your application's code so that you can customize what it does ... in this case, putting the auth interceptor into the /api route rather into the service's default interceptors (which puts auth before routing).
Awesome thanks! I literally have the default-service
function pulled up in my editor now to see how it works, I'll pull that logic out and modify as needed ๐
Alrighty, after a bit of hacking around I got it working! Now to clean it all up... Thanks again @U04VDKC4G
I've burned myself and many others by trying to create things that are both simple and endlessly customizable. In the end, you needed to internalize so much of the internals of such systems to be able to customize them that it was less work for everyone involved to do as we do here: use it initially, then cut-and-paste-and-modify.