This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-05
Channels
- # beginners (3)
- # boot (205)
- # cider (41)
- # clojars (1)
- # clojure (76)
- # clojure-colombia (1)
- # clojure-dusseldorf (3)
- # clojure-russia (314)
- # clojure-sg (1)
- # clojurebridge (1)
- # clojurescript (115)
- # css (2)
- # cursive (5)
- # editors (2)
- # funcool (2)
- # hoplon (18)
- # jobs (62)
- # jobs-discuss (28)
- # ldnclj (1)
- # leiningen (10)
- # mount (9)
- # off-topic (4)
- # om (93)
- # parinfer (10)
- # proton (1)
- # re-frame (19)
- # ring-swagger (18)
is anyone using compojure-api in combination with immutant-web? I’m a bit stuck figuring out how to pass my handler to the immutant web-server:
(require '[immutant.web :as server])
(defapi api-handler
(GET "/ping" []
(ok {:ping "pong"})))
(server/run api-handler {:host “localhost” :port 12345})
gives me
ClassCastException compojure.api.routes.Route cannot be cast to io.undertow.server.HttpHandler org.projectodd.wunderboss.web.undertow.UndertowWeb.registerHandler (UndertowWeb.java:68)
I’ve can test the routes themselves and they work as expected with:
(slurp (:body (api-handler {:request-method :get :uri “/ping”})))
Looks like Immutant is doing some magic to turn functions to handlers. Regular compojure and pre-1.0 compojure-api handler is normal function. In 1.0 it is special record which implements function interfaces.
https://github.com/immutant/immutant/blob/8d71cbff0cf3d2bee733c59d7eef8ffbb4fcfed2/web/src/immutant/web/internal/wunderboss.clj#L57-L63 they check against fn?
instead of ifn?
@ikitommi: tnx, (partial api-routes)
gives the same error, #(api-routes %)
works though
Though fn?
could be justified, but that's what causes it to not convert the handler to HttpHandler
You can manually convert the handler to HttpHandler by calling immutant.web.undertow/http-handler
Though I would have thought that #(...)
works also
well it compiles, maybe something else is going on, but somehow all of my routes (/ping, /swagger.json) return 404