Alexander Oloo

Alexander Oloo

Human. Engineer. Designer.

© 2019

< back

Gotcha! It's the trailing slash

You’ve discovered the Luminus framework. You’ve reached unparalleled levels of productivity. You can build a web app at the drop of a hat. You can’t believe no-one told you about this before. You’re life is perfect except for one small thing.

Every now and then an existing route returns a 404. It doesn’t make sense. The error only occurs some of the time. Should that even be possible? You want to pull you hair out…

GOTCHA! It’s the trailing slash!

Luminus relies on the awesome routing library by reitit. And reitit uses exact route matching. So /apply and /apply/ are two different routes. Therefore depending on how your end user enters the url, they may or may not get a 404.

Here’s how I fixed it:

(mount/defstate app
          {:path   "/swagger-ui"
           :url    "/api/swagger.json"
           :config {:validator-url nil}})
          {:path "/"})
          (wrap-webjars (constantly nil)))
        ; Here is it is => 
        (ring/redirect-trailing-slash-handler {:method :strip})
        ;<= and you're good to go

You can learn more about handling the trailing slash here.

May your build always pass.


This post is part of the “Advent of Parens”.

Today’s post is late courtesy of our wonderful electricity provider Eskom. Loadshedding is the best!