defmodule HAHandler.Web.Controller do import Plug.Conn alias HAHandler.{HAProxy, PGSQL} @templates_dir "lib/ha_handler/web/templates" defp render(conn, template, assigns) do template_path = Path.join(@templates_dir, template) quoted = EEx.compile_file(template_path) {body, _binding} = Code.eval_quoted(quoted, assigns) conn |> put_resp_content_type("text/html") |> send_resp(200, body) end def index(conn) do {:ok, hostname} = :net_adm.dns_hostname(:net_adm.localhost) stats = HAProxy.get_stats() assigns = [ haproxy_stats: stats, pgsql_status: PGSQL.status(), hostname: hostname, otp_app: HAHandler.otp_app(), version: HAHandler.version(), env: HAHandler.env() ] render(conn, "index.html.eex", assigns) end end