Fork me on GitHub
#ring
<
2023-11-12
>
DrLjótsson21:11:24

I’m trying to understand how the :context key for a ring request is handled by compojure. I can see that it’s read here https://github.com/weavejester/compojure/blob/1f921964801ef4ba45b7e694bc9c6a27394c1300/src/compojure/core.clj#L258 and passed on here https://github.com/weavejester/compojure/blob/1f921964801ef4ba45b7e694bc9c6a27394c1300/src/compojure/core.clj#L264, but I can’t really see where its value is used. The reason why I’m asking is that I have set the :context myself for another purpose, which completely broke my app. Now I’m trying to figure out where the breaking happens.

weavejester14:11:58

The context macro in Compojure, and the set-context function in Ring, split the :uri of a request map into a :context and :path-info parts.

weavejester14:11:57

So for example:

(compojure/context "/foo"
  (compojure/GET "/bar" []
    "This will match /foo/bar. The context is /foo, and the path-info is /bar"))

DrLjótsson14:11:33

Thanks! I was able to figure out that setting :context myself broke metosin's ring-swagger library. But I managed to solve it. 🙂

weavejester14:11:03

Yeah, that looks like a line that can be removed.

👍 1