Hello guys 👋! First of all thank you for reitit! It helped me a lot. How would you go about having all your server responses turned to camelCase (FE is in React). I want this to be automatic (something like a middleware) but is it possible to have middleware trigger after the handler function triggered?
Hey @ovidiu.stoica1094 I have something that may interest you. A moment and I'll push it up to github
<https://github.com/dharrigan/camel-case/blob/master/src/camel_case/main.clj>
hope it helps!
Hello! I'm trying (and failing) to use reitit frontend to force a re-direct to the "/" route if an unauthenticated user tries to directly navigate to a non-public route. For example "/#/entities/1" redirects to "/". Whats the best pattern for achieving this?
You do also have another option:
(require '[camel-snake-kebab.core :as csk])
(def m
(m/create
(assoc-in
m/default-options
[:formats "application/json" :encoder-opts]
{:encode-key-fn csk/->camelCase})))
(->> {:some-property "some-value"}
(m/encode m "application/json")
slurp)
; => "{\":someProperty\":\"some-value\"}"
where m
== muuntaja
Thank you very much @dharrigan!
You're most welcome 🙂
I have another example here, where you might like to strip away nil/empty values...
<https://github.com/dharrigan/strip-nils/blob/master/src/strip_nils/main.clj>
Hello @admarrs Hi, I have a very very very simple example, here...`https://github.com/dharrigan/startrek-ui/blob/master/src/startrek/main.cljs`
It doesn't do any backend authentication, simply relies upon a button to be pressed (that sets an atom) beforehand
if you try to navigate to "/#/the-queen"
directly, without pressing the button, you'll get a "go-away" page :)
You can see it running here: <https://startrek.harrigan.online/#/>
If you were to replace, line 34 in 'startrek.main', with [views/render]
, it would take the user back to the initial landing page
(thus, negating the need for the go-away page)
anyhoooo, it's just an example :-)
Hi @dharrigan, thanks for the example. Though it's more of a re-render than a re-direct since the go-away page is rendered on the /#/the-queen
route (i.e the url isn't re-directed). If that makes sense..
Sorted with a hat tip to @dharrigan by adding a push-state if user isn't defined:
(defn app
[]
(let [user @(subscribe [:user])
current-route @(subscribe [:current-route])]
(if-not user (rfe/push-state :home))
[:div
[nav {:current-route current-route}]
(when current-route
[(-> current-route :data :view)])]))
:thumbsup: