Fork me on GitHub
#reitit
<
2020-10-08
>
Steven Deobald12:10:33

What is the least-disgusting / most-compatible way to resolve route conflicts to keep URLs structured as Rails does?

["/pali_word_card" {:name ::pali-word-create
                    :post (wrap-spec-validation :entity/pali-word-request pali-word-handler/create)}]
;; conflicting:-
["/pali_word_card/new" {:name ::pali-word-new
                        :get  pali-word-handler/new}]
["/pali_word_card/:id" {:name ::pali-word-show
                        :get  pali-word-handler/show}]
:conflicts nil is a sledgehammer and even :conflicting true feels... heavy. Is there any other way around this?

ikitommi13:10:25

:conflicts nil is good and could have been the default option. If you have a route table with 100 routes and add a pair of conflicting routes, e.g. /pali_word_card/new & /pali_word_card/:id, those two will be isolated into a separate linear-router, all others will be served with best possible algo.

ikitommi13:10:59

the perf penalty for non-conflicting routes in that is one extra function call, few nanos in practise.

Steven Deobald13:10:38

oh, wait... conflict errors are to enable perf, not precision?

Steven Deobald13:10:21

(i was worried that :conflicts nil might cause errors)

ikitommi13:10:29

it’s precision in case you have a masked route, e.g.

[["/kikka/:id"]
 ["/kikka/kukka"]]
-> the second one is effective unreachable.

Steven Deobald13:10:55

rad. so as long as routes are in order, everything's golden?

Steven Deobald13:10:16

awesome! thanks

👍 3
ikitommi13:10:28

the conflict resolver could be smarter and know that

[["/kikka/kikka"]
 ["/kikka/:id"]]
actually is not conflicting as the fixed term(s) comes first. PR welcome 🙂

Steven Deobald13:10:25

🙂 i'll try to familiarize myself with all the parts of reitit before I try opening a PR. making a note, though.

delaguardo13:10:54

hi! i’m getting 404 for urls like this: /foo/../bar but /bar respond with 200 looks like reitit is not supporting single- and double-dot path segments, isn’t it?

ikitommi13:10:55

@delaguardo no, it’s not. you could have something (middleware etc) rewrite the url before it enters routing.

delaguardo13:10:52

this is how I solve it. wouldn’t it be too much impudence to ask for such a feature included (behind an option) in core router?

Steven Deobald14:10:54

@ikitommi fwiw, after 5 years away from clojure (and programming in general), it's nice to come back to the scene and find something like reitit. just replaced all my routing in the new app/service we're building and it honestly worked exactly as i've always wanted routing to work in clojure. thank you!

9