Fork me on GitHub
#luminus
<
2018-04-16
>
yogthos00:04:05

and let me know if you figure out what happened

adc1702:04:01

What is the purpose of wrap-context in middleware.clj? I see it sets the :servlet-context key of the params map used to render in layout.clj, which if I’ve understood correctly will adjust any links to from /foo/bar to /context/foo/bar. But if I’m right, what is the reason for using a dynamic binding to do this?

yogthos12:04:26

@alexchalk17 there are two use cases for this, one is if you're running inside an app server like jboss, where the context is provided at runtime, the other is if you decide to front multiple apps on the same domain with nginx or something

yogthos12:04:43

and you don't need it to be dynamic in that case

adc1714:04:00

@yogthos, I’m still not sure I get it—in the jboss example, what stops you from querying the application context directly in layout.clj? Does it change during runtime?

yogthos14:04:14

It doesn't, but all the routes have to use the prefix, it just the layout ones

adc1714:04:53

in my template *app-context* is only used in layout.clj?

adc1714:04:07

is it because in the jboss scenario you can’t define *app-context* in the render logic without passing in http request info? so the dynamic binding is a neater way of letting the rendering logic access a definition made in another part of the application?

yogthos16:04:22

yeah basically

yogthos16:04:39

it allows specifying the context via the middleware, and then accessing that context wherever it's needed

yogthos17:04:12

it might be better to just stick it as a key on the request though, that logic has been there for a while, and I haven't used it myself in ages

yogthos17:04:47

I'll take a look at getting rid of the dynamic var, those are always a bit of a smell 🙂

yogthos17:04:34

although then you would have to pass the request to the render function in layout for all requests

adc1719:04:02

thanks @yogthos, that makes sense now. I’m still pretty new to clojure, and discovering dynamic vars was a bit of a wtf moment 😛, but I agree that it is more elegant than always passing the req to the render function.

yogthos20:04:49

it looks like the whole app server idea is going away anyways now that containers are popular, if you're making a green field project then it's much better to just have a jvm per app in my opinion

yogthos20:04:12

especially now that jdk 10 plays nice with containers 🙂