Because BackendTask's in elm-pages
never run in the browser (see the BackendTask docs), you can access environment variables securely. As long as the environment variable isn't sent
down into the final Data
value, it won't end up in the client!
import BackendTask exposing (BackendTask)
import BackendTask.Env
type alias EnvVariables =
{ sendGridKey : String
, siteUrl : String
}
sendEmail : Email -> BackendTask ()
sendEmail email =
BackendTask.map2 EnvVariables
(BackendTask.Env.expect "SEND_GRID_KEY")
(BackendTask.Env.get "BASE_URL"
|> BackendTask.map (Maybe.withDefault "http://localhost:1234")
)
|> BackendTask.andThen (sendEmailBackendTask email)
sendEmailBackendTask : Email -> EnvVariables -> BackendTask ()
sendEmailBackendTask email envVariables =
Debug.todo "Not defined here"
Get an environment variable, or a BackendTask failure if there is no environment variable matching that name.
Get an environment variable, or Nothing if there is no environment variable matching that name.