Add override format query param

This commit is contained in:
Shadowfacts 2020-04-23 18:46:50 -04:00
parent 7d071d971c
commit 77bca46197
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 14 additions and 1 deletions

View File

@ -4,7 +4,20 @@ defmodule ClacksWeb.Plug.Format do
def init(opts), do: opts def init(opts), do: opts
def call(conn, _opts) do def call(conn, _opts) do
format = Phoenix.Controller.get_format(conn) 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
assign(conn, :format, format) assign(conn, :format, format)
end end
end end