From 2a9f5da5dff319613463841bdae79f32ba24a3ce Mon Sep 17 00:00:00 2001 From: Marco Russo Date: Sat, 14 Dec 2024 15:23:08 +0100 Subject: [PATCH] feat: Final OTP application --- lib/servy.ex | 9 +++++---- lib/servy/kickstarter.ex | 3 ++- mix.exs | 5 ++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/servy.ex b/lib/servy.ex index afe2bc5..b8e479c 100644 --- a/lib/servy.ex +++ b/lib/servy.ex @@ -1,7 +1,8 @@ defmodule Servy do - def hello(name) do - "Howdy, #{name}!" + use Application + + def start(_type, _args) do + IO.puts "Starting the application..." + Servy.Supervisor.start_link() end end - -IO.puts Servy.hello("Elixir") diff --git a/lib/servy/kickstarter.ex b/lib/servy/kickstarter.ex index 70c5682..a26b9de 100644 --- a/lib/servy/kickstarter.ex +++ b/lib/servy/kickstarter.ex @@ -20,7 +20,8 @@ defmodule Servy.Kickstarter do defp start_server do IO.puts "Starting the HTTP server..." - server_pid = spawn_link(Servy.HttpServer, :start, [4000]) + port = Application.get_env(:servy, :port) + server_pid = spawn_link(Servy.HttpServer, :start, [port]) Process.register(server_pid, :http_server) server_pid end diff --git a/mix.exs b/mix.exs index f68d0d0..88b34c7 100644 --- a/mix.exs +++ b/mix.exs @@ -4,6 +4,7 @@ defmodule Servy.MixProject do def project do [ app: :servy, + description: "A humble HTTP server", version: "0.1.0", elixir: "~> 1.17", start_permanent: Mix.env() == :prod, @@ -14,7 +15,9 @@ defmodule Servy.MixProject do # Run "mix help compile.app" to learn about applications. def application do [ - extra_applications: [:logger, :eex, :observer, :wx, :runtime_tools] + extra_applications: [:logger, :eex, :observer, :wx, :runtime_tools], + mod: {Servy, []}, + env: [port: 3000] ] end