Packages

Check your application health

Current section

Files

Jump to
health_check_plug lib health_check_plug.ex
Raw

lib/health_check_plug.ex

defmodule HealthCheckPlug do
@moduledoc """
Check your application health by always return 200 with the body `{"status":"ok"}`.
It is useful to setup monitoring tools that hit this endpoint to check if you app is alive.
## Usage
Add the healthcheck into your phoenix router:
```elixir
# router.ex
forward "/monitoring/health_check", HealthCheckPlug
```
"""
@behaviour Plug
import Plug.Conn
@impl Plug
def init(opts), do: opts
@impl Plug
def call(conn, _opts) do
body = ~S({"status":"ok"})
conn
|> put_resp_header("content-type", "application/json")
|> send_resp(200, body)
|> halt()
end
end