Fork me on GitHub
#reitit
<
2019-04-10
>
ikitommi11:04:27

@roklenarcic oh, would you have a time to do a PR to fix that?

roklenarcic11:04:57

@ikitommi I think the issue is that I'm using rring/create-resource-handler outside of a router, I am using it as a default handler. This is why path-params key is missing and path is always nil.

ikitommi11:04:31

oh, sure. so, you could write it as:

(rring/ring-handler
  (rring/router
    [["/status" {:get {:handler (json/wrap-json-response status-handler)}}]
     ["/api" {:middleware (api-middleware logger)}
      ["" {:get {:handler api-handler}}]]]
    (rring/create-resource-handler {}))
  {:middlewre [wrap-gzip wrap-head]})

roklenarcic11:04:49

that's the same?

roklenarcic11:04:20

but router doesn't take a default handler

roklenarcic11:04:26

the second param is opts map

roklenarcic11:04:46

and ring-handler takes a default handler but not an opts map

ikitommi11:04:55

(ring/ring-handler
  (ring/router
    [["/status" {:get {:handler (json/wrap-json-response status-handler)}}]
     ["/api" {:middleware (api-middleware logger)}
      ["" {:get {:handler api-handler}}]]])
  (ring/create-resource-handler {})
  {:middlewre [wrap-gzip wrap-head]})

roklenarcic11:04:11

yeah, but that's what I had and that doesn't work

roklenarcic11:04:44

because resource handler doesn't receive :path-params in request map

roklenarcic11:04:42

It looks for path param : (empty keyword) in :path-params key in request

roklenarcic11:04:51

this is absent

ikitommi11:04:50

you need to set the :path argument.

ikitommi11:04:58

(def app
  (ring/ring-handler
    (ring/router
      ["/status" {:get {:handler (constantly {:status 200, :body "ok"})}}])
    (ring/create-resource-handler {:path "/"})))

(app {:request-method :get, :uri "/docs"})

roklenarcic11:04:01

code here:

(if (resource-response (join-paths path file))
                                               (response/redirect (join-paths uri file))
is odd though. Why use a different expression for full path in if and the clause

roklenarcic11:04:51

Looks like it works now

roklenarcic11:04:11

in doc it says | :path | optional path to mount the handler to. Works only if mounted outside of a router.

roklenarcic11:04:28

should probably say that it's mandatory outside of a router

ikitommi12:04:42

yes, it should.

ikitommi12:04:14

could you make a PR?