Fork me on GitHub
#cljsrn
<
2018-03-10
>
Kara01:03:38

Is there a good way to store and load (non-committed) local environment variables? I tried using: https://www.npmjs.com/package/react-native-dotenv but I couldn't get it to work with re-natal... I just have a filepath I need to manually set for development, but its different on each of my computers.

mfikes01:03:47

@kara if you are using Lein you could consider using :closure-defines with ~(System/getenv "MY_ENV_VAR"). You'd at least have to commit changes to your project.clj and the usage sites, but the actual value of MY_ENV_VAR can vary from box to box.

Kara01:03:44

cool! That sounds like a good lead. Yeah, I'm Ok with commit the setup but the value I just didn't want in the repo since it's local system stuff. 😛

Kara22:03:04

hi @U04VDQDDY... I was wondering if I could ask a follow up question on this... In the documentation for :closure-defines it says: > Vars must be specified as a namespace-qualified symbol, and their values must be a string, number, or a boolean but are you saying I can also use a function that resolves to one of those values? For example... I found this library: https://github.com/LynxEyes/dotenv.clj which is pretty much exactly what I'd like... but I need to "inject" the .env variables into clojurescript... could I do something like :closure-defines {"MY_ENV_VAR" ~(env "MY_ENV_VAR")} per your example? I'm using lein figwheel

mfikes22:03:53

Yes, the use of ~(env ...) is great, but the key should be namespace qualified, pointing to the var established by goog-define in your code

mfikes22:03:32

Do (doc goog-define) to see what I mean

Kara22:03:13

ah, yes! I see that now. Ok, thanks. hopefully this works 🤞:skin-tone-2: 🙂

jeaye01:03:45

@kara We just use environ and load them with macros during compile-time.

Kara01:03:15

enviorn? 🙂

jeaye01:03:20

So there's a gitignored config.edn with all the secrets and it's loaded via macros.

mfikes01:03:58

That works too... just be aware that if you put code like that into a JAR that you re-use, then it won't be cache-friendly (ClojureScript's 1.10.x shared AOT cache feature)

Kara01:03:03

I don't think that's an issue for me... I'm trying to go after the '12 Factor App pattern' as stated in the readme so that seems to align with my specific use case

jeaye01:03:39

Also, I realized I was multitasking and provided two bad answers. We have two solutions, depending on the usage. For long-term secrets, we use a gitignored config.edn which is slurped at run-time, but that's only on the back-end. On the front-end, we use environ and bring in the secrets at macro expansion.

Kara01:03:47

> bring in the secrets at macro expansion Let's pretend I have no idea what I'm doing here. 🙃 Is this basically saying... when the function is called it reads the value from the source?

Kara01:03:58

really my use case is pretty simple. While I'm doing local development I want to change a path from the default (some crazy path nested in simulator) to somewhere else on my machine I can find the file. So in my case... ./data/develoment.realm but it needs a full path. I can just manually put in the path, but as I switch systems it's a headache and I don't really want it in the final codebase

Kara01:03:18

I feel like... environ will work for this