Skip to content

Commit f361cbd

Browse files
committed
feat: add config
1 parent ee07c54 commit f361cbd

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

config/config.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Config
2+
3+
if Mix.env() == :test do
4+
import_config "test.exs"
5+
end

config/test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Config
2+
3+
config :web_push_elixir,
4+
vapid_public_key: "someVapidPublicKey",
5+
vapid_private_key: "someVapidPrivateKey",
6+
vapid_subject: "mailto:admin@email.com"

lib/web_push_elixir.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ defmodule WebPushElixir do
8080
JOSE.JWT.from_map(%{
8181
aud: URI.parse(endpoint).scheme <> "://" <> URI.parse(endpoint).host,
8282
exp: DateTime.to_unix(DateTime.utc_now()) + 12 * 3600,
83-
sub: System.get_env("VAPID_SUBJECT")
83+
sub: Application.get_env(:web_push_elixir, :vapid_subject)
8484
})
8585

8686
json_web_key =
@@ -108,8 +108,8 @@ defmodule WebPushElixir do
108108
Returns the result of `HTTPoison.post`
109109
"""
110110
def send_notification(subscription, message) do
111-
vapid_public_key = url_decode(System.get_env("VAPID_PUBLIC_KEY"))
112-
vapid_private_key = url_decode(System.get_env("VAPID_PRIVATE_KEY"))
111+
vapid_public_key = url_decode(Application.get_env(:web_push_elixir, :vapid_public_key))
112+
vapid_private_key = url_decode(Application.get_env(:web_push_elixir, :vapid_private_key))
113113

114114
%{endpoint: endpoint, keys: %{p256dh: p256dh, auth: auth}} =
115115
Jason.decode!(subscription, keys: :atoms)

test/web_push_elixir_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ defmodule WebPushElixirTest do
1010
vapid_subject: vapid_subject
1111
} = Mix.Tasks.Generate.Vapid.Keys.run([])
1212

13-
System.put_env("VAPID_PUBLIC_KEY", vapid_public_key)
13+
Application.put_env(:web_push_elixir, :vapid_public_key, vapid_public_key)
1414

15-
System.put_env("VAPID_PRIVATE_KEY", vapid_private_key)
15+
Application.put_env(:web_push_elixir, :vapid_private_key, vapid_private_key)
1616

17-
System.put_env("VAPID_SUBJECT", vapid_subject)
17+
Application.put_env(:web_push_elixir, :vapid_subject, vapid_subject)
1818

1919
{:ok, response} = WebPushElixir.send_notification(@subscription, "some message")
2020

0 commit comments

Comments
 (0)