Fork me on GitHub
#reitit
<
2019-05-21
>
ikitommi10:05:02

@petr - @juhoteperi knows how how the re-frame should work

Gabe Koss12:05:19

hello. very new here! I am attempting to use interceptors in reitit-http to do an auth validation very similar to the auth-interceptor here: https://metosin.github.io/reitit/interceptors.html . I am trying to figure out how to make the request short circuit and return a 403 as it seems like the example implies. The conditional mounting of the interceptor is working fine and it assoc's a 403 to the response but then it is still passed to the handler which ultimately 200s (in my test handler, the real handler will error and 500 without being passed user info) Maybe I should just be doing this with regular middleware and interceptors aren't ready for primetime? New to the ecosystem so I'm trying to figure out what pattern to follow. TL;DR Are there any good working patterns of getting interceptors to short circuit requests on the :enter function or should I take a different angle?

ikitommi12:05:05

@gabe.koss the docs on reitit-http are really non-existent, mostly on sieppari side. Here’s how to do it now:

:interceptors [{:enter (fn [ctx]
                         (if (-> ctx :request :parameters :query :x (> 10))
                           (-> ctx
                               (assoc :response {:status 404, :body "invalid"})
                               (assoc :queue nil))))}]
, e.g. empty the (unprocesses) queue and assoc a response.

ikitommi12:05:48

will be most likely:

:interceptors [(fn [ctx]
                 (cond-> ctx
                         (-> ctx :request :parameters :query :x (> 10))
                         (s/terminate {:status 404, :body "invalid"})))]
with the upcoming new sieppari release (not planned, maybe after summer?).

ikitommi12:05:01

sieppari should get proper docs, function will map to :enter and helpers to manipulate the context. also, order of magnitude faster, for simple chains, it will be faster than with using clojure.core/comp, which is kinda crazy.

Gabe Koss13:05:27

Awesome! I'll give that a shot! I was going down a similar shot and I had just started inspecting the context map in more depth in order to see if i could nil out the handler somehow but I was looking at [:request :reitit.core/match :data :get] which (as you'd imagine) had no impact 🙂 I had completely missed queue.

👍 4
Gabe Koss13:05:09

Totally worked like a charm. Thanks @ikitommi

PB18:05:59

Does anyone know of a way to force controllers to re-load

valtteri19:05:08

Or do you mean re-load as something like figwheel code re-load?

PB19:05:54

Ah I misread the docstring there

PB19:05:59

This might work , thank you