Fork me on GitHub

@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?


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


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


@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.


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


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)
     (let [result (handler req)]
       (when after
         (log-fn {:after after}))
     ;;  (catch Exception e
     ;;    (clojure.pprint/pprint {:exception e :msg msg :after after})
     ;;    (throw e)))

👍 4

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:


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


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

👍 4

nice, looking forward to that!


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


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


can’t remember now


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 -


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