230 | 230 |
it with the request as a parameter. (This code is largely copied from the
|
231 | 231 |
bidi upstream, but we add support for inserting the match-context via
|
232 | 232 |
middleware.)"
|
233 | |
([route handler-fn]
|
234 | |
(fn [{:keys [uri path-info] :as req}]
|
235 | |
(let [path (or path-info uri)
|
236 | |
{:keys [handler route-params] :as match-context}
|
237 | |
(or (:match-context req)
|
238 | |
(apply bidi/match-route route path (apply concat (seq req))))]
|
239 | |
(when handler
|
240 | |
(bidi-ring/request
|
241 | |
(handler-fn handler)
|
242 | |
(-> req
|
243 | |
(update-in [:params] merge route-params)
|
244 | |
(update-in [:route-params] merge route-params))
|
245 | |
(apply dissoc match-context :handler (keys req))
|
246 | |
)))))
|
247 | |
([route] (make-handler route identity)))
|
|
233 |
[route]
|
|
234 |
(fn [{:keys [uri path-info] :as req}]
|
|
235 |
(let [path (or path-info uri)
|
|
236 |
{:keys [handler route-params] :as match-context}
|
|
237 |
(or (:match-context req)
|
|
238 |
(apply bidi/match-route route path (apply concat (seq req))))]
|
|
239 |
(when handler
|
|
240 |
(bidi-ring/request
|
|
241 |
handler
|
|
242 |
(-> req
|
|
243 |
(update-in [:params] merge route-params)
|
|
244 |
(update-in [:route-params] merge route-params))
|
|
245 |
(apply dissoc match-context :handler (keys req)))))))
|
248 | 246 |
|
249 | 247 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
250 | 248 |
;;; Private - helpers for compojure-like syntax
|
|
315 | 313 |
|
316 | 314 |
(schema/defn ^:always-validate
|
317 | 315 |
routes->handler :- (schema/pred fn?)
|
318 | |
"Given a bidi route tree, converts into a ring request handler function. You
|
319 | |
may pass an optional handler function which will be wrapped around the
|
320 | |
bidi leaf."
|
321 | |
([routes :- bidi-schema/RoutePair
|
322 | |
handler-fn :- (schema/maybe (schema/pred fn?))]
|
323 | |
(let [compiled-routes (bidi/compile-route routes)]
|
324 | |
(make-handler compiled-routes handler-fn)))
|
325 | |
([routes]
|
326 | |
(routes->handler routes identity)))
|
|
316 |
"Given a bidi route tree, converts into a ring request handler function"
|
|
317 |
[routes :- bidi-schema/RoutePair]
|
|
318 |
(let [compiled-routes (bidi/compile-route routes)]
|
|
319 |
(make-handler compiled-routes)))
|
327 | 320 |
|
328 | 321 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
329 | 322 |
;;; Public - compojure-like convenience macros
|