Fork me on GitHub
#reitit
<
2019-01-28
>
ikitommi12:01:59

thanks @tommi.jalkanen, lot’s of typos 🙂

koura12:01:00

no problem

ikitommi12:01:59

and everyone, feel free to contribute to docs, if something is written poorly or missing.

defa19:01:00

Is there a way (frontend) to prevent a route from “executing” and redirecting to an other route. I’d like to redirect to a login-component if not authenticated or if the user has the wrong role. Is that possible? I was experimenting with route data and controllers but don’t know how to redirect.

juhoteperi19:01:36

@defa My experience is that is better to keep authentication outside of routing. For rendering something like (if authenticated [routing-view] [login-view]) and for controllers, only enable them after user is authenticated or something.

juhoteperi19:01:50

This way after authentication is done, user is at the correct route by default, and you don't need to redirect user back to previous view after login.

juhoteperi19:01:43

And you can enhance this to take into account views that don't need authentication via route-data: (if (or authenticated (:public route-data)) [routing-view] [login-view])

defa19:01:17

@juhoteperi you’re right, that seems to be much simpler than having a dedicated route for a login panel.

juhoteperi19:01:24

I guess we should have an example of this in the repo

defa19:01:48

@juhoteperi Thank you very much. An example would be a good nice for beginners. Took me a while to find #reitit as an alternative to secretary which seems to be pretty basic.

kanwei20:01:26

how does route conflict actually work?

kanwei20:01:27

/api/assets/swagger/*
                        -> /api/assets/*

kanwei20:01:33

does it route by longest first?

kanwei20:01:00

docs say you can override with :conflicts nil but doesn't explain what happens

ikitommi20:01:12

@kanwei reitit keeps the routes in order. For conflicting route tree, a :qurantine-router is created, which runs all the conflicting routes with :linear-router, so they are matched in order.

kanwei20:01:03

order as defined in the router vector?

kanwei20:01:28

or as shown in the conflict list

ikitommi20:01:20

the router vector. you can ask the routes with r/routes. with ring, it’s (-> app reitit.ring/get-router reitit.core/routes)

kanwei20:01:24

how bad of a performance hit is a quarantine router?

ikitommi20:01:20

if you have 1000 routes with 2 conflicts, the 998 (non-conflicting) will be as fast as route table with 998 without conflicts.

ikitommi20:01:18

the 2 will be matched in order with a compiled Trie, so 99% as fast without conflicts.

ikitommi20:01:28

basically, it’s near zero penalty.

ikitommi20:01:02

just benchmarking the next :trie-router which will replace the :segment-router and it’s 20-40% faster.

ikitommi20:01:17

really like the flamegraphs for perf tuning.