Page MenuHomePhorge

No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/fast_html/application.ex b/lib/fast_html/application.ex
index 48f6696..ba4c0db 100644
--- a/lib/fast_html/application.ex
+++ b/lib/fast_html/application.ex
@@ -1,53 +1,65 @@
defmodule FastHtml.Application do
@moduledoc false
use Application
def random_sname, do: :crypto.strong_rand_bytes(4) |> Base.encode16(case: :lower)
def start(_type, _args) do
case maybe_setup_node() do
{:error, message} -> raise message
_ -> :ok
end
Supervisor.start_link([FastHtml.Cnode], strategy: :one_for_one, name: FastHtml.Supervisor)
end
defp maybe_setup_node() do
with {_, false} <- {:alive, Node.alive?()},
{:ok, epmd_path} <- find_epmd(),
:ok <- start_epmd(epmd_path),
{:ok, _pid} = pid_tuple <- start_node() do
pid_tuple
else
{:alive, _} ->
:ok
{:error, _} = e ->
e
end
end
defp find_epmd() do
case System.find_executable("epmd") do
nil ->
{:error,
"Could not find epmd executable. Please ensure the location it's in is present in your PATH or start epmd manually beforehand"}
executable ->
{:ok, executable}
end
end
defp start_epmd(path) do
case System.cmd(path, ["-daemon"]) do
{_result, 0} -> :ok
{_result, exit_code} -> {:error, "Could not start epmd, exit code: #{exit_code}"}
end
end
+ defp hostname() do
+ {:ok, ifaddrs} = :inet.getifaddrs()
+
+ ifaddrs
+ |> Enum.filter(fn {_name, value} -> :loopback in Keyword.get(value, :flags) end)
+ |> Enum.at(0)
+ |> elem(1)
+ |> Keyword.get(:addr)
+ |> :inet.ntoa()
+ |> to_string()
+ end
+
defp start_node() do
- Node.start(:"master_#{random_sname()}@127.0.0.1")
+ Node.start(:"master_#{random_sname()}@#{hostname()}")
end
end

File Metadata

Mime Type
text/x-diff
Expires
Fri, Oct 9, 9:32 PM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1784885
Default Alt Text
(1 KB)

Event Timeline