Fork me on GitHub
#yada
<
2016-07-12
>
martinklepsch16:07:54

in bidi, how can I combine to route descriptions like the one below:

(defn handler [sys]
  ["/" {"subscriptions" {:post (fn [req] {:status 200 :body "create-sub-handler"})}
        ["subscriptions/" :id] {:get (fn [req] {:status 200 :body "get-sub-handler"})
                                :delete (fn [req] {:status 200 :body "delete-sub-handler"})}}])
(defn handler' [sys]
  ["/" {"customers" {:post (fn [req] {:status 200 :body "create-sub-handler"})}
        ["customers/" :id] {:get (fn [req] {:status 200 :body "get-sub-handler"})
                                :delete (fn [req] {:status 200 :body "delete-sub-handler"})}}])

martinklepsch16:07:03

I guess the simplest way is to just strip the "/" stuff and do something like ["/" (merge (handler {}) (handler' {}))]

martinklepsch18:07:41

hm but now I'm stuck trying to figure out how to add a catch all route:

(bidi/match-route [["/" {"subscriptions"        {:post (fn [req] (prn sys) {:status 200 :body "create-sub-handler"})}
                         ["subscriptions/" :id] {:get (fn [req] (prn sys) {:status 200 :body "get-sub-handler"})
                                                 :delete (fn [req] (prn sys) {:status 200 :body "delete-sub-handler"})}}]
                   [true #(rres/not-found "Not found")]]
                  "asds")
This throws. I tried a few variations of this but none worked.. 😝

richiardiandrea19:07:45

@martinklepsch: I don't know if it can help, but this is something similar I am doing:

"admin" {"" (fn [_] (ring/redirect "/admin/login.html"))
                 "/" (fn [_] (ring/redirect "/admin/login.html"))
                 true spa-response}

martinklepsch19:07:27

@richiardiandrea: this brought me on the right track I think, thanks!

martinklepsch20:07:27

I really wish there would be better errors for stuff like this: java.lang.IllegalArgumentException: No implementation of method: :segment-regex-group of protocol: #'bidi.bidi/PatternSegment found for class: clojure.lang.PersistentArrayMap Fighting a weird error that only occurs when using the routing table with make-handler...