Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use debux with Ring middleware #33

Open
devurandom opened this issue Jan 3, 2025 · 1 comment
Open

How to use debux with Ring middleware #33

devurandom opened this issue Jan 3, 2025 · 1 comment

Comments

@devurandom
Copy link

Ring middleware are functions look like:

(defn wrap-me
  [handler msg]
  (fn [request]
    ;; `identity` represent the logic of the middleware:
    (identity (handler (identity request)))))

They are applied like:

(-> handler
    (wrap-me "one")
    (wrap-me "two")
    (wrap-me "three")
    ,,,)

Is there a convenient way to apply debux to print in each step the request fed to and the response returned by the handler?

I would hope for something like the following to be possible:

(dbgmw (-> handler
           (wrap-me "one")
           (wrap-me "two")
           (wrap-me "three")
           ,,,)))
; Would print something like:
; dbgmw: (-> handler (wrap-me "one") (wrap-me "two") (wrap-me "three") ,,,)
; | request => {,,,}
; | (wrap-me ,,, "three") => {,,,}
; | (wrap-me ,,, "two") => {,,,}
; | (wrap-me ,,, "one") => {,,,}
; | (handler ,,,) => {,,,}
@philoskim
Copy link
Owner

philoskim commented Jan 6, 2025

Debux doesn't have such a feature you mentioned.

Instead, I recommend the following code snippet to you.

(use 'debux.core)

(defn wrap-dbg [handler middleware-name]
  (fn [req]
    (dbg req :msg (str "request to " middleware-name))
    (let [resp (handler req)]
      (dbg resp :msg (str "response from " middleware-name))
      resp) ))

(-> handler
    (wrap-me "one")
    (wrap-dbg "wrap-me one")
    (wrap-me "two")
    (wrap-dbg "wrap-me two")
    (wrap-me "three")
    (wrap-dbg "wrap-me three")
    ,,,)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants