Fork me on GitHub
#reitit
<
2018-09-13
>
levitanong12:09:12

@ikitommi So i’m running into problems with reitit and ring-cors. Turns out, when I include wrap-cors in a middleware field, preflight requests fail unless :options is set as a field on an endpoint. Wrapping wrap-cors around ring-handler works, but it ends up clobbering the metadata, which means I have to do the meta and with-meta dance to get around it. Is there a more idiomatic way to go about this?

ikitommi13:09:51

@levitanong could you write an issue out of that with a failing sample? Currently on #clojutre, could check out later.

grierson14:09:22

how do I log incoming requests so that I can debug why I'm getting a nil response?

ikitommi15:09:36

@grierson good question. For now, the reitit.ring/create-default-handler knows wether the nil originated from route miss, method-missing or a handler returning nil.

ikitommi15:09:31

you can also investigate the created route tree to see which paths handle what methods

manutter5115:09:26

I used some custom middleware to trace things

(defn wrap-checkpoint
  "Dev tool to print diagnostic msgs as request flows thru middleware."
  [handler msg & [after]]
  (let [log-fn #(log/trace %) ] ; Move to config
    (fn [req]
     (log-fn msg)
     ;;(try
     (let [result (handler req)]
       (when after
         (log-fn {:after after}))
       result)
     ;;  (catch Exception e
     ;;    (clojure.pprint/pprint {:exception e :msg msg :after after})
     ;;    (throw e)))
     )))

👍 1
ikitommi15:09:30

there is also an option to modify the middleware chain, e.g. interleave a debugging mw between every mw (if the reason would be ill-behaving mw. Guide: https://metosin.github.io/reitit/ring/transforming_middleware_chain.html

manutter5115:09:38

Is that recent? I don’t remember seeing that when I wrote my custom middleware (which was a while ago tbh)

ikitommi15:09:50

plan is to build a kick-ass dev-tool, which would expose all the routing artefacts via a web-tool. Will allow a request to be inspected or modified step-by-step. Kinda like a routing debugger/doc tool

👍 1
manutter5115:09:37

nice, looking forward to that!

ikitommi15:09:04

I think the mw chain trasformation option has been since 0.1.0?

manutter5115:09:57

I might have just missed it, or else I wanted the functionality to put specific “before” and “after” messages around each piece of middleware.

manutter5115:09:02

can’t remember now

aaron5123:09:41

Why does ring.middleware.file/wrap-file not work inside :data :middleware in ring/ring-handler? It only works for me if I put it outside of ring-handler. Demo - https://gist.github.com/apeckham/d70e08e4dcc54dfd1531b94f1fbc267e

aaron5123:09:18

(By “works” I mean returns the contents of the file as expected. “Doesn’t work” = returns a 404 instead)