Fork me on GitHub
#reitit
<
2021-04-16
>
lsenjov00:04:20

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

wombawomba12:04:04

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.

manutter5112:04:36

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.

wombawomba12:04:28

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?

manutter5112:04:07

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).

manutter5112:04:10

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).

manutter5112:04:33

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

manutter5112:04:47

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

wombawomba12:04:31

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

wombawomba12:04:53

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 in my browser works (I get the static page), but clicking a link like <a href="/docs>Docs</a> 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?

wombawomba12:04:37

...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 🙂

wombawomba12:04:34

Yup, that did the trick

👍 3
Xarlyle013:04:11

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))))

Xarlyle021:04:00

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)