Browse Source

Move listen port to config file

master
Piotr Orzechowski 7 months ago
parent
commit
b1ee0a42c8

+ 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, 4040

+ 8
- 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,11 @@ defmodule KVServer.Application do
opts = [strategy: :one_for_one, name: KVServer.Supervisor]
Supervisor.start_link(children, opts)
end

defp listen_port do
case System.get_env("KV_PORT") do
nil -> Application.fetch_env!(:kv_server, :listen_port)
port -> String.to_integer(port)
end
end
end

+ 1
- 0
apps/kv_server/mix.exs View File

@@ -19,6 +19,7 @@ defmodule KVServer.MixProject do
def application do
[
extra_applications: [:logger],
env: [listen_port: 4040],
mod: {KVServer.Application, []}
]
end

Loading…
Cancel
Save