Skip to content

Commit

Permalink
fix: environment variables not loading on app config (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodiaslobo authored Jan 10, 2025
1 parent 40f64b3 commit 7756e0f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
6 changes: 1 addition & 5 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import Config

config :safira,
ecto_repos: [Safira.Repo],
generators: [timestamp_type: :utc_datetime],
from_email_name: System.get_env("FROM_EMAIL_NAME") || "SEI",
from_email_address: System.get_env("FROM_EMAIL_ADDRESS") || "[email protected]",
umami_script_url: System.get_env("UMAMI_SCRIPT_URL") || "",
umami_website_id: System.get_env("UMAMI_WEBSITE_ID") || ""
generators: [timestamp_type: :utc_datetime]

# Flop configuration
config :flop,
Expand Down
6 changes: 6 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ if System.get_env("PHX_SERVER") do
config :safira, SafiraWeb.Endpoint, server: true
end

config :safira,
from_email_name: System.get_env("FROM_EMAIL_NAME") || "SEI",
from_email_address: System.get_env("FROM_EMAIL_ADDRESS") || "[email protected]",
umami_script_url: System.get_env("UMAMI_SCRIPT_URL") || "",
umami_website_id: System.get_env("UMAMI_WEBSITE_ID") || ""

if config_env() in [:prod, :stg] do
database_url =
System.get_env("DATABASE_URL") ||
Expand Down
9 changes: 4 additions & 5 deletions lib/safira/accounts/user_notifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ defmodule Safira.Accounts.UserNotifier do

alias Safira.Mailer

@from_name Application.compile_env!(:safira, :from_email_name)
@from_email Application.compile_env!(:safira, :from_email_address)

# Delivers the email using the application mailer.
defp deliver(recipient, subject, body) do
sender = {Mailer.get_sender_name(), Mailer.get_sender_address()}

email =
new()
|> to(recipient)
|> from({@from_name, @from_email})
|> subject("[#{@from_name}] #{subject}")
|> from(sender)
|> subject("[#{elem(sender, 0)}] #{subject}")
|> text_body(body)

with {:ok, _metadata} <- Mailer.deliver(email) do
Expand Down
8 changes: 8 additions & 0 deletions lib/safira/mailer.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
defmodule Safira.Mailer do
use Swoosh.Mailer, otp_app: :safira

def get_sender_name do
Application.get_env(:safira, :from_email_name)
end

def get_sender_address do
Application.get_env(:safira, :from_email_address)
end
end
4 changes: 2 additions & 2 deletions lib/safira_web/components/layouts/landing.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</script>
<script
defer
src={Application.fetch_env!(:safira, :umami_script_url)}
data-website-id={Application.fetch_env!(:safira, :umami_website_id)}
src={Application.get_env(:safira, :umami_script_url)}
data-website-id={Application.get_env(:safira, :umami_website_id)}
/>
</head>
<body class="bg-primary text-light font-iregular">
Expand Down
4 changes: 2 additions & 2 deletions lib/safira_web/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</script>
<script
defer
src={Application.fetch_env!(:safira, :umami_script_url)}
data-website-id={Application.fetch_env!(:safira, :umami_website_id)}
src={Application.get_env(:safira, :umami_script_url)}
data-website-id={Application.get_env(:safira, :umami_website_id)}
/>
</head>
<body>
Expand Down

0 comments on commit 7756e0f

Please sign in to comment.