|
1 | 1 | (ns compojure.api.core |
2 | 2 | (:require [compojure.api.meta :as meta] |
| 3 | + [compojure.api.async] |
3 | 4 | [compojure.api.routes :as routes] |
4 | 5 | [compojure.api.middleware :as mw] |
5 | 6 | [compojure.core :as compojure] |
6 | 7 | [clojure.tools.macro :as macro])) |
7 | 8 |
|
8 | | -(defn- handle [handlers request] |
9 | | - (some #(% request) handlers)) |
| 9 | +(defn ring-handler |
| 10 | + "Creates vanilla ring-handler from any invokable thing (e.g. compojure-api route)" |
| 11 | + [handler] |
| 12 | + (fn |
| 13 | + ([request] (handler request)) |
| 14 | + ([request respond raise] (handler request respond raise)))) |
10 | 15 |
|
11 | 16 | (defn routes |
12 | 17 | "Create a Ring handler by combining several handlers into one." |
13 | 18 | [& handlers] |
14 | | - (let [handlers (seq (keep identity handlers))] |
15 | | - (routes/create nil nil {} (vec handlers) (partial handle handlers)))) |
| 19 | + (let [handlers (seq (keep identity (flatten handlers)))] |
| 20 | + (routes/map->Route |
| 21 | + {:childs (vec handlers) |
| 22 | + :handler (meta/routing handlers)}))) |
16 | 23 |
|
17 | 24 | (defmacro defroutes |
18 | 25 | "Define a Ring handler function from a sequence of routes. |
|
35 | 42 | not satisfying compojure.api.routes/Routing -protocol." |
36 | 43 | [& handlers] |
37 | 44 | (let [handlers (keep identity handlers)] |
38 | | - (routes/create nil nil {} nil (partial handle handlers)))) |
| 45 | + (routes/map->Route {:handler (meta/routing handlers)}))) |
39 | 46 |
|
40 | 47 | (defmacro middleware |
41 | 48 | "Wraps routes with given middlewares using thread-first macro. |
|
67 | 74 | {:childs [handler] |
68 | 75 | :handler x-handler}))) |
69 | 76 |
|
70 | | -(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true})) |
| 77 | +(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true :&form &form :&env &env})) |
71 | 78 |
|
72 | 79 | (defmacro GET {:style/indent 2} [& args] (meta/restructure :get args nil)) |
73 | 80 | (defmacro ANY {:style/indent 2} [& args] (meta/restructure nil args nil)) |
|
0 commit comments