Fork me on GitHub
#reitit
<
2019-04-09
>
andfadeev10:04:06

hi everyone! need some help with reitit pedestal, trying to do some tests based on this guide http://pedestal.io/guides/pedestal-with-component currently this works

(deftest some-test
  (let [service-fn (get-in *system* [reitit/pedestal-reitit-http :server :io.pedestal.http/service-fn])
        response (response-for service-fn :get "/math/plus?x=1&y=2")]
    
    (is (= {:status 200
            :body "{\"total\":3}"}
           (select-keys response [:status :body])))))
but I still can't find a way to use io.pedestal.http.route/url-for-routes to generate string url from reitit routes map(

ikitommi11:04:38

@andfadeev hi. You should use the reitit.core/match-by-name instead. But it requires the instance of the router, which is not exposed into the context map. Wrote an issue of that: https://github.com/metosin/reitit/issues/255 & will fix that this week. For now, if you have a handle to thet reitit.http/router, you can just use that:

(-> router
    (reitit.core/match-by-name ::ping)
    (reitit.core/match->path))
; "/ping"

andfadeev11:04:31

thanks! i guess i can put instance of router in component along with actual http server and access it in test, I will try

ikitommi11:04:15

did you get it working?

andfadeev11:04:00

yes, thanks!

roklenarcic15:04:47

Is there a bug in here?

(defn router [logger]
  (rring/router
    [["/status" {:get {:handler (json/wrap-json-response status-handler)}}]
     ["/api" {:middleware (api-middleware logger)}
      ["" {:get {:handler api-handler}}]]]))

  (rring/ring-handler (router logger)
    (-> (rring/create-resource-handler {})
      wrap-gzip
      wrap-head))

roklenarcic15:04:02

so this should get index.html from public folder

roklenarcic15:04:12

when request is to /

roklenarcic15:04:01

instead this happens when I point the browser to localhost

roklenarcic15:04:40

2019-04-09/15:14:30.805/UTC Roks-MacBook-Pro-3.local INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/", :query-string nil}
2019-04-09/15:14:46.483/UTC Roks-MacBook-Pro-3.local INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/index.html", :query-string nil}
2019-04-09/15:14:52.087/UTC Roks-MacBook-Pro-3.local INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/index.html/index.html", :query-string nil}
2019-04-09/15:14:52.103/UTC Roks-MacBook-Pro-3.local INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/index.html/index.html/index.html", :query-string nil}
2019-04-09/15:14:52.112/UTC Roks-MacBook-Pro-3.local INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/index.html/index.html/index.html/index.html", :query-string nil}
2019-04-09/15:14:52.119/UTC Roks-MacBook-Pro-3.local INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/index.html/index.html/index.html/index.html/index.html", :query-string nil}
2019-04-09/15:14:52.128/UTC Roks-MacBook-Pro-3.local INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/index.html/index.html/index.html/index.html/index.html/index.html", :query-string nil}

roklenarcic15:04:15

I am confused, why does it keep redirecting?

roklenarcic15:04:12

This resource-response call keeps hitting /index.html while it completely ignores uri getting longer and longer and longer

roklenarcic15:04:58

so it doesn;t matter which uri is passed into this function, if there's an index file present it will redirect

roklenarcic15:04:44

for some reason path is always null

hairfire20:04:04

How does one specify a swagger response with an empty body? For example for a response code of 204, which has not body.

hairfire20:04:15

I just discovered the answer. Simply use something like {... :responses {204 nil} ...}

ikitommi13:04:32

That could be good example in the docs, if you have to for a PR.