Fork me on GitHub
#shadow-cljs
<
2019-12-17
>
cfleming03:12:03

I have a website which talks to an API backend, both are CLJS using shadow. In my pages I make calls to the backend, in production they will call https://<my-domain>/path, but in local dev I want them to call . Is there a tidy way to do this? I thought about using the hosts file but that doesn’t allow me to switch from https to http or specify the port to use.

cfleming03:12:07

Actually it looks like Closure defines would work for this. So am I correct in thinking that if I do this:

(goog-define LOCAL true)
(def api-target (if LOCAL "<local-url>" "<prod-url>")
Then only one of those values will be compiled into the code? Or am I better to have the URL itself as the value of the define?

superstructor04:12:21

Yes your correct only one value should be compiled in when using Closure defines.

superstructor04:12:56

Personally I inject the entire URL, instead of just a boolean, but I believe either way will have the same result i.e. only one value compiled in to the output JS.

cfleming08:12:10

@U0G75S29H Thanks, yes, that’s what I ended up with, which seems to work well.

superstructor15:12:31

Anytime @U0567Q30W 🙂 Thank you for Cursive! I spend about 50% of my time awake using it.

cfleming23:12:16

Great, I’m glad you’re still liking it!

mikerod21:12:40

what’s the purpose of the ^clj type hint?