Browse Source

Move listen port to config file

undefined
Piotr Orzechowski 7 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
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env()}.exs"

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
use Application

def start(_type, _args) do
port = String.to_integer(System.get_env("KV_PORT") || "4040")
port = listen_port()
# List all child processes to be supervised
children = [
{Task.Supervisor, name: KVServer.TaskSupervisor},
@@ -20,4 +20,8 @@ defmodule KVServer.Application do
opts = [strategy: :one_for_one, name: KVServer.Supervisor]
Supervisor.start_link(children, opts)
end

defp listen_port() do
Application.fetch_env!(:kv_server, :listen_port)
end
end

Loading…
Cancel
Save