Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: environment variables not loading on app config #457

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading