clacks/lib/clacks_web/plug/format.ex

24 lines
458 B
Elixir
Raw Normal View History

2019-10-06 23:41:18 +00:00
defmodule ClacksWeb.Plug.Format do
import Plug.Conn
def init(opts), do: opts
def call(conn, _opts) do
2020-04-23 22:46:50 +00:00
conn = fetch_query_params(conn)
format =
case conn.query_params do
%{"format" => format} when format in ["activity+json", "html"] ->
format
%{"format" => "json"} ->
"activity+json"
_ ->
Phoenix.Controller.get_format(conn)
end
2019-10-06 23:41:18 +00:00
assign(conn, :format, format)
end
end