Fork me on GitHub
#juxt
<
2017-04-26
>
Yehonathan Sharvit08:04:33

@jonpither waiting for your comments…

jonpither08:04:55

to way to achieve this currently is to make a Mach extension

jonpither08:04:29

I'll knock up an example for you

jonpither08:04:28

the target bar is imported from the ext1.mach.edn file, with properties assigned

dominicm09:04:48

@viebel I'll have to use this myself for our training machfile. Gotta oss that thing 🙂

minikomi10:04:19

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?

dominicm10:04:43

@minikomi if you move the [[keyword :lang] "/" … before the ["" common-routes…] does that solve your problem?

minikomi10:04:01

oh.. will try 🙂

minikomi10:04:05

seems like it! nice one hahha

dominicm10:04:38

@minikomi the reason is that bidi checks in order.

minikomi10:04:28

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.

dominicm10:04:32

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.

minikomi10:04:13

Yeah, I went down route one for a little while but ended up having too much string / keyword juggling for my liking.

dominicm10:04:33

Does a middleware like this not solve it:

(defn coerce-lang
  [handler]
  (fn [req]
    (handler (update-in req [:route-params :lang] keyword)))

minikomi10:04:27

Oops, just found out that having the [keyword :lang] version first means that not having a :lang keyword throws an exception.

minikomi10:04:51

ie. fails fast, rather than keeps looking

dominicm10:04:17

Hmm, then it should check your second set of routes under ["" common-routes-map]

dominicm11:04:31

Oh. That makes sense.

dominicm11:04:55

Yes, I've never considered that. :thinking_face:

minikomi11:04:24

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)))

minikomi11:04:17

A bit tricky, since I want to capture it if it exists, ignore it if it’s not there..

dominicm11:04:05

I'm not sure what bidi's rules are about duplicate handlers in a route structure tbh.

minikomi11:04:39

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

Yehonathan Sharvit13:04:25

@jonpither what is the best way to deploy a clojure web server (catacumba) to aws beanstalk?

Yehonathan Sharvit13:04:10

Is it still relevant?

jonpither13:04:40

@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

jonpither13:04:05

We moved away from Beanstalk

jonpither13:04:16

and we use Terraform to provision a beanstalk-like environment

Yehonathan Sharvit13:04:46

My customer requires beanstalk 😬

jonpither13:04:29

if beanstalk is a hard-fast, then the approach in the blog above should still work

Yehonathan Sharvit13:04:38

Is there a way to deploy the uberjar directly to beanstalk - without docker?

dominicm13:04:32

@viebel I think beanstalk has it's own wrapper.

dominicm13:04:36

that isn't docker

jonpither13:04:42

beanstalk takes either a WAR or a Dockerfile

dominicm13:04:43

but docker is a pretty convenient format in comparison

Yehonathan Sharvit13:04:22

how do I setup docker on macos?

jonpither13:04:38

yeah should work

jonpither13:04:48

I had it working well, but I'm on linux now

dominicm13:04:15

docker for mac is a lot better than it used to be, I hear.

jonpither13:04:52

my experience was it was changing a lot also