Fork me on GitHub
#reitit
<
2021-01-20
>
paulbutcher00:01:21

I suspect I’m missing something, but I’m unable to get the :not-found-handler option for reitit.ring/create-resource-handler to work: it doesn’t look like the function is called at all. I’ve created a minimal cut-down version of my application which demostrates the problem: https://github.com/paulbutcher/reitit-bug The relevant code is:

(def handler
  (ring/ring-handler
   (ring/router
    ["/ping" {:get (constantly (response "pong"))}])
   (ring/routes
    (ring/create-resource-handler {:path "/"
                                   :not-found-handler (fn [x]
                                                        (println "not found handler: " x)
                                                        (-> "index.html"
                                                            (resource-response {:root "public"})
                                                            (content-type "text/html")))})
    (ring/create-default-handler))))
What am I missing?

Steven Deobald19:01:09

@paulbutcher Just passing by but at a glance, my routes file has :not-found in the default handler itself:

(rr/create-default-handler
     {:not-found          (constantly {:status 404, :body "404: Not Found."})
      :method-not-allowed (constantly {:status 405, :body "405: Method Not Allowed."})
      :not-acceptable     (constantly {:status 406, :body "406: Not Acceptable."})})

paulbutcher22:01:03

Thanks @steven427. I’m aware that that’s possible too (and indeed that’s the solution that I’ve settled on). But create-resource-handler claims to also support this functionality and doesn’t seem to be working for me at least.