Skip to content

Commit

Permalink
Add healthcheck route
Browse files Browse the repository at this point in the history
  • Loading branch information
KauanCarvalho authored Feb 13, 2024
2 parents 3e712c5 + db2c427 commit 4a84661
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule BackendFightWeb.HealthcheckController do
use BackendFightWeb, :controller

alias DB.Repo
alias Ecto.Adapters.SQL

def index(conn, _params) do
{:ok, _result} = check_database()

conn |> send_resp(200, "")
end

defp check_database, do: SQL.query(Repo, "select 1", [])
end
4 changes: 4 additions & 0 deletions apps/backend_fight_web/lib/backend_fight_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ defmodule BackendFightWeb.Router do
pipe_through :api
end

scope "/", BackendFightWeb do
get("/healthcheck", HealthcheckController, :index)
end

# Enable LiveDashboard and Swoosh mailbox preview in development
if Application.compile_env(:backend_fight_web, :dev_routes) do
# If you want to use the LiveDashboard in production, you should put
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule BackendFightWeb.HealthcheckControllerTest do
use BackendFightWeb.ConnCase

test "GET /healthcheck, when everything happens as it should, it is expected to return 200 without a body", %{
conn: conn
} do
conn = conn |> get("/healthcheck")

assert "" = response(conn, 200)
end
end

0 comments on commit 4a84661

Please sign in to comment.