Fork me on GitHub
#luminus
<
2017-05-29
>
eoliphant04:05:35

hi, quick question, I’ve created a re-frame, etc app, I need to make some config variables avaiable on the client, but the config namespace and the env state are only on the pure clojure side, what’s the best way to make some of the vars available on the client?

yogthos13:05:46

if your variables are known at compile time, you could use a cljc file to store them

yogthos13:05:31

if it's something that's read at runtime, it's probably easiest to set them on the page as json, if you're using selmer, you could do something like

<script type="text/javascript">
    var identity = {{identity|json|safe}};    
</script>
Then when you initialize re-frame db, you can read those as the initial values:
(def default-db
  {:identity (when js/identity (js->clj js/identity :keywordize-keys true))})

vetalik14:05:58

Hello! How can i add CORS support ? I found several middle wares but could not get them working

eoliphant14:05:46

Hi @yogthos, in this case I guess they’re more runtime, or potentially runtime as some might need to be overridden at deployment, third-party API keys, etc

yogthos14:05:03

ideally you don't want to send sensitive data to the client if you can avoid it, but if you have to then it's probably best to send it using an ajax request once the user with proper credentials is logged in

eoliphant14:05:28

yeah, exactly, I don’t want everything to be available on the client, but for instance we’re using Auth0 for authentication, so the client js library needs an API key, etc. Though that’s of course a bit of a chicken/egg problem lol. Since in that specific case, the client needs that stuff before you’re logged in. I’ll play around with it. This seems like it might be a common requirement. I’m wondering if there’s a need for a more standard way, like some sort of cprop adapter/wrapper for the client, that would only ask the server for some demarcated subset of vars. I’ve done some work with meteor, they have a pretty simplistic approach where only values under a ‘public’ key are available on the client

vetalik14:05:17

Hello @eoliphant can i add CORS support for luminus? My UI app is not located within same url as backend, I need allow UI to receive data I found this lib: https://github.com/jumblerg/ring.middleware.cors But information there is not enough for me. I don;t understand Ring good enough yet

eoliphant14:05:31

Hi, @vetalik I’ve not had to deal with that scenario myself, and my Ring is pretty basic as well. There’s a dedicated #ring channel though, you should probably be able to get more help there.

yogthos15:05:27

@eoliphant yeah it should be easy enough to plug into cprop, let me know once you play around with it, I'm definitely open to adding something to make this simpler

yogthos15:05:29

it looks to be actively maintained

eoliphant15:05:28

cool will do. Luminus has really been an awesome help in terms of easing entry into the Clojure web world. I been a Java/J2EE programmer for as long as they’ve been around, so like many folks I was kind of like “Where’s Spring?” when I got started lol. Would love to give somethign back

vetalik15:05:09

I got solution. Quite easy. I was adding handler incorreclty