2
votes

Is there a way to return a response from the router without going through a controller? I have tried a few different methods with no success.

scope "/health_check", ZB do
  get "/" do
    text conn, "ok"
  end
end

get "/health_check" do
  text conn, "ok"
end
1
I don't think there is; all routing related functions in Phoenix.Router require a plug and plug_opts: github.com/phoenixframework/phoenix/blob/master/lib/phoenix/…Dogbert

1 Answers

3
votes

I got it two work by creating a new file called health_check_router.ex with this:

defmodule ZB.HealthCheckRouter do
  use Plug.Router

  plug :match
  plug :dispatch

  get "/" do
    send_resp(conn, 200, "ok")
  end
end

and adding this at the bottom of router.ex:

forward "/health_check", ZB.HealthCheckRouter

Source: https://elixirforum.com/t/phoenix-router-inline-controllers/727/3