This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-17
Channels
- # announcements (10)
- # aws (10)
- # babashka (11)
- # beginners (77)
- # calva (9)
- # cider (10)
- # cljdoc (7)
- # cljs-dev (47)
- # clojure (47)
- # clojure-uk (4)
- # clojurescript (87)
- # community-development (15)
- # conjure (14)
- # core-async (25)
- # cursive (6)
- # fulcro (6)
- # helix (3)
- # joker (2)
- # nrepl (1)
- # off-topic (1)
- # pathom (9)
- # pedestal (6)
- # re-frame (22)
- # reitit (15)
- # shadow-cljs (26)
- # spacemacs (16)
- # testing (2)
- # tools-deps (12)
- # uncomplicate (10)
- # xtdb (22)
I have an API key that I don’t want to commit to my source control.
What is the best way to “inject” values at compile time?
Ideally different values for dev
and prod
builds.
I could find anything in the re-frame and shadow-cljs docs.
I found https://shadow-cljs.github.io/docs/UsersGuide.html#closure-defines but they seem also to be static in the config files.
you can override it dynamically via https://shadow-cljs.github.io/docs/UsersGuide.html#config-merge
but I generally recommend keeping "runtime configuration" out of the build completely and instead actually configure it at runtime
eg. you set <script>
in your HTML and access it via js/window.MY_APP_CONFIG.key
in your code
Sorry I think I am being slow. > eg. you set <script>http://window.MYAPPCONFIG = {key: “foo”};</script> in your HTML Doesn’t that require me to put it into my repo again?
--config-merge
seems to be something I can do on my build server with env variables.
Do you recommend against doing that?
No sorry, so far I am working on a plain old client-side SPA
if you really want to turn it into a compile time constant then you can. either --config-merge
or env vars work
you can also load the config dynamically at runtime if you don't want to put it into the HTML
as I said ... many different ways to go about this. don't know enough about your app to know what would work for you.
Yeah, maybe a bit more context is useful. I want to write a little authenticated multi collaborator ToDo app, but I want to make it open source. Therefore I don’t want to commit my authentication pool Ids (Using AWS Cognito) to the repository. But ideally provide a simple step on how anyone could create their own user pool and set their ids.
eg. you create an index.sample.html
with some instruction on what to do with it to create the "real" index.html
Alright, I did that with my config.js file and it works like a charm. Thank you so much 🙂
Nice, I like that. I could also make the script it’s own file and provide a sample. Then it should be relatively easy to provide the real file on a build server. Thank you for your help, I’ll see how I get on 🙂
I do something similar to the above, but implement it differently so that I have something that works in dev (local machine) and other envs. Have a file in the public dir called parms.json with all the config in a json map. When developing (I use shadow-cljs, but will work with anything) I do a GET /params.json to get runtime params . When I build for test/staging/prod (same docker for each) I have nginx serving my cljs app, and I have a section in the nginx.conf that uses envsubst to serve the same structure as params.json, but for the environment. That way I let env vars drive things.