Browse Source

Move listen port to config file

undefined
Piotr Orzechowski 3 months ago
parent
commit
bd91c40b90
2 changed files with 7 additions and 1 deletions
  1. 2
    0
      apps/kv_server/config/config.exs
  2. 5
    1
      apps/kv_server/lib/kv_server/application.ex

+ 2
- 0
apps/kv_server/config/config.exs View File

@@ -28,3 +28,5 @@ use Mix.Config
28 28
 # here (which is why it is important to import them last).
29 29
 #
30 30
 #     import_config "#{Mix.env()}.exs"
31
+
32
+config :kv_server, :listen_port, String.to_integer(System.get_env("KV_PORT") || "4040")

+ 5
- 1
apps/kv_server/lib/kv_server/application.ex View File

@@ -6,7 +6,7 @@ defmodule KVServer.Application do
6 6
   use Application
7 7
 
8 8
   def start(_type, _args) do
9
-    port = String.to_integer(System.get_env("KV_PORT") || "4040")
9
+    port = listen_port()
10 10
     # List all child processes to be supervised
11 11
     children = [
12 12
       {Task.Supervisor, name: KVServer.TaskSupervisor},
@@ -20,4 +20,8 @@ defmodule KVServer.Application do
20 20
     opts = [strategy: :one_for_one, name: KVServer.Supervisor]
21 21
     Supervisor.start_link(children, opts)
22 22
   end
23
+
24
+  defp listen_port() do
25
+    Application.fetch_env!(:kv_server, :listen_port)
26
+  end
23 27
 end

Loading…
Cancel
Save