From 32116fe2c98480be32d2967fd91ea96efafa7ad2 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Fri, 27 May 2022 10:49:04 +0300 Subject: [PATCH] Show database library in info endpoint --- .../controllers/api/external_controller.ex | 28 +++++++++++++++++++ lib/plausible_web/router.ex | 1 + 2 files changed, 29 insertions(+) diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.ex index 7b13eb90b..070d77630 100644 --- a/lib/plausible_web/controllers/api/external_controller.ex +++ b/lib/plausible_web/controllers/api/external_controller.ex @@ -55,6 +55,34 @@ defmodule PlausibleWeb.Api.ExternalController do }) end + def info(conn, _params) do + version_file = Application.app_dir(:plausible, "priv/static/version.json") + + version = + with {:ok, file} <- File.read(version_file), + {:ok, json} <- Jason.decode(file) do + json + else + _ -> %{} + end + + geo_database = + case Geolix.metadata([:geolocation]) do + %{geolocation: %{database_type: type}} -> + type + + _ -> + "(not configured)" + end + + info = + Map.merge(version, %{ + geo_database: geo_database + }) + + json(conn, info) + end + defp parse_user_agent(conn) do user_agent = Plug.Conn.get_req_header(conn, "user-agent") |> List.first() diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex index a66abf7b2..ac04b287d 100644 --- a/lib/plausible_web/router.ex +++ b/lib/plausible_web/router.ex @@ -113,6 +113,7 @@ defmodule PlausibleWeb.Router do post "/event", Api.ExternalController, :event get "/error", Api.ExternalController, :error get "/health", Api.ExternalController, :health + get "/info", Api.ExternalController, :info post "/paddle/webhook", Api.PaddleController, :webhook