Switching out "dev" and "prod" environments with deps.edn

We were all clojure newbies once. And, tbh, it took me a while to figure out the same things you are struggling with. So I definitely empathize.

There is nothing explicit like what you suggest. The “magic” happens because there is a different CLASSPATH and deps.edn aliases in prod and dev. Also, since I am using juxt/aero (which I recommend) there is just one config that covers both dev and prod.

A while ago, I put up a pair of repos on github that has a barebones front-end and back-end that I used to learn some technologies. You might find these repos instructive to understand how the switch between dev and prod works in a deps.edn project. The repos are Hix (front-end) and Hax (back-end API server). For your needs, the Hax repo would be more appropriate.

Look at hax/resources/system.edn which is the config file. Note this excerpt:

{:port #profile
   {:prod 5555
    :dev 5554
    :test 5556}

What that says to juxt/aero is to use port 5555 for prod, 5554 for dev, and 5556 for the test environments.

The Usage section of the README shows you how to run the hax server in the dev and prod environments. Note that each invocation uses a different alias in the deps.edn.

Finally, if you look at hax.clj, you’ll see that, by default, the prod profile is used to set up the config.

If you look at user.clj, which is automatically loaded if it is on the CLASSPATH (which it is in the dev alias), you will see that the the dev profile is passed to the config processing in the set-prep! function.

Hope this helps. If not, please ask further questions.

1 Like