This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-24
Channels
- # announcements (30)
- # asami (9)
- # babashka (37)
- # beginners (120)
- # calva (26)
- # cider (3)
- # clara (9)
- # clj-commons (7)
- # clj-kondo (17)
- # cljsrn (2)
- # clojure (32)
- # clojure-europe (56)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-uk (4)
- # clojurescript (34)
- # conjure (1)
- # copenhagen-clojurians (8)
- # core-async (21)
- # cursive (2)
- # datahike (2)
- # datascript (5)
- # events (4)
- # fulcro (32)
- # graalvm (10)
- # heroku (3)
- # introduce-yourself (1)
- # jobs (2)
- # lsp (3)
- # luminus (1)
- # malli (8)
- # meander (15)
- # minecraft (1)
- # nrepl (2)
- # off-topic (57)
- # pathom (2)
- # polylith (35)
- # reagent (6)
- # reitit (8)
- # releases (1)
- # rewrite-clj (7)
- # shadow-cljs (21)
- # timbre (4)
- # tools-build (1)
- # tools-deps (33)
- # vrac (8)
Hello! I'm having an issue with adding coercion middleware (but since I'm very new to all of this, I'm having trouble explaining my problem correctly 🥲) I'm currently building a webapp on top of the luminus template for lein and when I add my own middleware to a route, it seems to overwrite(?) or generally stop the template's error reporting middleware. It's very likely that with how the template handles middleware that I can't just add
:middleware [foo]
as I'd like to, but I'm hopeful that there's an easy fix 🙂Oh, after fiddling with it, I think that it's because I'm registering two exception handling middleware at the same time (the coercion one is a merge of the default handlers and one looking for request-coercion errors).
Does anyone know of a way to make these two play nicely?
Could someone help me understand what it means here https://cljdoc.org/d/metosin/reitit/0.5.15/doc/coercion/coercion-explained#compiling-coercers
> Before the actual coercion, we should need to compile the coercers against the route data. Compiled coercers yield much better performance and the manual step of adding a coercion compiler makes things explicit and non-magical.
I see you need to provide a corecion/compile-rquest-coercers value
(require '[reitit.coercion :as coercion])
(require '[reitit.coercion.schema])
(require '[schema.core :as s])
(def router
(r/router
["/:company/users/:user-id" {:name ::user-view
:coercion reitit.coercion.schema/coercion
:parameters {:path {:company s/Str
:user-id s/Int}}}]
{:compile coercion/compile-request-coercers}))
So compiling happens before run time, what can be done here that isn't at run time as the search param arguments need to be changed at run time?> The compiler added a :result
key into the match (done just once, at router creation time), which holds the compiled coercers. We are almost done.
i'm confused, wouldn't that cljs coercion functions get compiled by the compiler normally to a js object?
@drewverlee router compilation happens at language runtime: route tree, models and middleware/interceptor/controller chains are read from the (data-)definitions and optimized pure functions are returned. If you need to change those definitions, you need to re-create the router - or use dynamic routing, which is described in the docs.
as an example are we saying that when the routes are compiled
{:path {:company s/Str :user-id s/Int}}
is turned into (fn [company user-id] ...)