@jonpither waiting for your comments…
hi @viebel
to way to achieve this currently is to make a Mach extension
I'll knock up an example for you
thx
@viebel have a look at https://github.com/juxt/mach/blob/master/examples/extensions/Machfile.edn
the target bar is imported from the ext1.mach.edn file, with properties assigned
It works like a charm @jonpither @dominicm 👏
@viebel I'll have to use this myself for our training machfile. Gotta oss that thing 🙂
Definitely
Hi there. I’m using bidi on the frontend (great combo!), and trying to encode a set of routes in a way which would make it easier for me to do i18n.
I have a map of routes like {"" :home "about/" :about}
etc. and, in front of that, there’s either a [/ :lang /]
, or just a “/”, which would mean the default language.
So, I tried:
(def app-routes
["/" [["" common-routes-map]
[[[keyword :lang] "/"] common-routes-map]
[true :404]]])
And it works great, the lang is captured in a keyword, and the shared routes show up on the handlers, but in generating routes the :lang
-less route is taking precedence wether the :lang
keyword is present or not.. I’ve been trying quite a few different workarounds but most feel too clever.
Is there a better way to “encode” the route along the lines of what I want to achieve?@minikomi if you move the [[keyword :lang] "/" …
before the ["" common-routes…]
does that solve your problem?
oh.. will try 🙂
seems like it! nice one hahha
@minikomi the reason is that bidi checks in order.
Yep got it! Makes sense. I wonder if there’s a way to restrict the value of the keyword? If not i can just check within the app on navigation.
I'm not certain off the top of my head, but you have 2 options:
- Use a regex and use a middleware to coerce it to a keyword
- Look at how the regex/fn validators are implemented within bidi, most of bidi is extensible, you may be able to just drop your own function in there & return false
when it doesn't match.
Yeah, I went down route one for a little while but ended up having too much string / keyword juggling for my liking.
Does a middleware like this not solve it:
(defn coerce-lang
[handler]
(fn [req]
(handler (update-in req [:route-params :lang] keyword)))
Oops, just found out that having the [keyword :lang]
version first means that not having a :lang
keyword throws an exception.
ie. fails fast, rather than keeps looking
Hmm, then it should check your second set of routes under ["" common-routes-map]
Oh. That makes sense.
Yes, I've never considered that. :thinking_face:
The other way around it is use the original order then a fn like:
(defn to [handler &{:keys [lang]
:as params}]
(let [url (b/unmatch-pair i18n-routes {:handler handler
:params (dissoc params :lang)})]
(if lang (str "/" (name lang) url)
url)))
A bit tricky, since I want to capture it if it exists, ignore it if it’s not there..
I'm not sure what bidi's rules are about duplicate handlers in a route structure tbh.
yeah, seems a bit sketchy but it makes for nice routes / logic throughout - can just check a :lang value to change some things but keep most of the structure of the app the same
certainly
@jonpither what is the best way to deploy a clojure web server (catacumba) to aws beanstalk?
Your article is quite old https://juxt.pro/blog/posts/beanstalk.html
May 2015
Is it still relevant?
@viebel we have a new approach, I literally 50% through the blog. I can take you through it if you want - it's a bit alpha tho
We moved away from Beanstalk
and we use Terraform to provision a beanstalk-like environment
My customer requires beanstalk 😬
if beanstalk is a hard-fast, then the approach in the blog above should still work
Is there a way to deploy the uberjar directly to beanstalk - without docker?
no
@viebel I think beanstalk has it's own wrapper.
that isn't docker
beanstalk takes either a WAR or a Dockerfile
but docker is a pretty convenient format in comparison
how do I setup docker on macos?
with brew?
yeah should work
I had it working well, but I'm on linux now
docker for mac is a lot better than it used to be, I hear.
my experience was it was changing a lot also