reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
lsenjov 2021-04-16T00:51:20.092300Z

Question: does your ring-session cookie change when returning from oauth?

wombawomba 2021-04-16T12:03:04.096300Z

So I've set up a ring handler via

(reitit.ring/ring-handler
 (reitit.ring/router my-routes)
 (reitit.ring.routes/create-file-handler {:root fs-root, :path "/"))
and I'm running into a problem where one of my routes (`/:foo/:bar`) is shadowing my static assets served via the file handler. Is there a way around this? I.e. can I get the static assets to have higher priority than this route? I can't really change either this route or the path of the static assets.

2021-04-16T12:10:36.097600Z

Have a look at https://github.com/ring-clojure/ring/wiki/Creating-responses, I think you should be able to make a custom “static resource handler” fairly easily using ring.util.response, and hopefully it would play nicely with your other routes.

wombawomba 2021-04-16T12:14:28.098200Z

Hmm yeah that looks like it could work.. although wouldn't that mean that we'd have to enumerate all the static files we're serving?

2021-04-16T12:30:07.099400Z

Not necessarily, you can still put wildcards in the path like with any other route, and then it’s up to your custom handler to take care of making sure the resource actually exists (and returning nil if it doesn’t).

2021-04-16T12:31:10.100200Z

Though I haven’t tried anything like that and I’m assuming reitit will move on to the next matching route if your handler returns nil (which is what compojure does).

2021-04-16T12:31:33.100600Z

I’d have to go back and dig thru the reitit docs to be sure.

2021-04-16T12:31:47.101Z

or you could just try it and see if all your routes work right 😄

wombawomba 2021-04-16T12:33:31.101300Z

alright, I'll give that a shot, thanks 🙂

wombawomba 2021-04-16T12:39:53.105400Z

I actually have another issue as well: I'm using reitit.frontend.easy, and I have some routes serving static assets that it's currently picking up but that I would like it to ignore. For instance, opening <http://my-backend/docs> in my browser works (I get the static page), but clicking a link like &lt;a href="/docs&gt;Docs&lt;/a&gt; from a Reitit-controlled page doesn't — because Reitit intercepts the URL change so the static page never gets loaded. How can I get around this?

wombawomba 2021-04-16T12:41:37.106400Z

...actually, I just saw that there's a :ignore-anchor-click? option to reitit.frontend.easy/start! that I think I should be using for this. I'll give that a shot now 🙂

wombawomba 2021-04-16T12:42:34.106700Z

Yup, that did the trick

👍 1
Xarlyle0 2021-04-16T13:41:11.109200Z

Hello! I'm trying to make a basic swagger ui using reitit-swagger-ui but the webpage gives me an error and I just can't seem to figure out why. I'm generally copying from this project: https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj And the code is this:

(def app
  (ring/ring-handler
   (ring/router
    [["/swagger.json"
      {:get {:no-doc true
             :swagger {:id "2.0"
                       :info {:title "my-api"
                              :description "something"}}
             :handler (swagger/create-swagger-handler)}}]
     ["/api"
      {:swagger {:id :my-api}}

      ["/checkImage"
       {:post {:summary ""
               :parameters {:multipart {:file multipart/temp-file-part}}
               :responses {200 {:body {:errors true}}}
               :swagger {:consumes ["image/jpg"]}
               :handler checkImage}}]]]
    {:data {:middleware [swagger/swagger-feature
                         multipart/multipart-middleware]}})
   (ring/routes
    (swagger-ui/create-swagger-ui-handler
     {:path "/"})
    (ring/create-default-handler))))

Xarlyle0 2021-04-16T21:21:00.111Z

Okay I figured out that the problem was that I didn't have the correct middleware. However I believe it should be in the reitit docs which middlewares are required for these simple cases to work! (I'm actually not sure which middleware did the trick)