Here is how I am setting things up to deploy to different environments.
I define a Config module which specifies all the parameters of the environment:
type alias Config =
{ applicationContextRoot : String
, apiRoot : String -- The main API being consumed.
, avatarApiRoot : String -- Another API.
, ... -- More APIs...
}
I also write a config decoder:
configDecoder : Decoder Config
configDecoder = ...
At the top-level I use programWithFlags, and pass in the config as a Value in the flags, and decode it to a Config.
The config parameters can be put in a .js file, under an environment specific directory, like env described by Richard, and set things up so that the index.html containing the Elm application can pick that up on a known relative path from the web server.
<script src="env/params.js"></script>
OR I set up the back-end server that serves up the index.html to generate that index.html dynamically, and inject the correct parameters.
It is worth getting used to the fact that APIs in development and APIs in test/production are going to be in different locations, so always write your API calls in this format:
getUser : String -> UserId -> Request User
postUser : String -> User -> Request User
deleteUser : String -> UserId -> Request ()
You can also easily write a default Config for development, that would supply “” for the API root locations.