These are chat archives for jescalan/roots

20th
Jul 2016
Wes Vetter
@wesvetter
Jul 20 2016 17:51
Greetings all! I have what I think is a straight-forward question. I have Javascript config variables (ie. API keys) that are specific to the deployment environment. My intuition is to use the locals property of app.*.coffee files and then export them via !script = var FOO_KEY = ... in my template. Is this the standard way exposing config variables to Javascript or is there someway of directly accessing a config variable from app.coffee?
Jeff Escalante
@jescalan
Jul 20 2016 18:14
hi @wesvetter -- yup that is the standard way of doing it
Wes Vetter
@wesvetter
Jul 20 2016 18:15
I'm not super familiar with Jade, but is there any easier way of exporting a dict beyond foo = {}, foo.bar = ...; foo.baz = ..., having to do a fair amount of string concatenation here.
Wes Vetter
@wesvetter
Jul 20 2016 18:29
Looks like I can do this: script!= "var ENV = '" + JSON.stringify(locals) + "'; ENV = JSON.parse(ENV);", not sure if there's a cleaner way but that's probably clean enough. I can't imagine I'm the first with environment specific JS variables so it might be worth mentioning in the docs.
Jeff Escalante
@jescalan
Jul 20 2016 22:26
yup thats the way i do it
script!= "var ENV = " + JSON.stringify(locals) will do it
no need for the parse etc
you can run that later in your script
Tom Kraak
@tkraak
Jul 20 2016 22:45
@wesvetter are you able to get into more details on what this is being used for? would love to learn
Wes Vetter
@wesvetter
Jul 20 2016 22:47
I'm integrating with Stripe and some other APIs, and for development I have a development config with a test API key and some other development-specific values, and then for production I have the real keys.
they're public keys & values, so it's fine to have them in git (ie. I don't need true environment variables), but I do need them environment-specific
Tom Kraak
@tkraak
Jul 20 2016 22:59
@wesvetter thanks!
Wes Vetter
@wesvetter
Jul 20 2016 23:19
@tkraak @jescalan I can make a pull-request for docs if you think that'd be helpful
Tom Kraak
@tkraak
Jul 20 2016 23:23
please do! :gift: