dcbabc9df00ff8ee07354afe39d52cca0359043e
[akkoma] / lib / pleroma / plugs / static_fe_plug.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Plugs.StaticFEPlug do
6 def init(options), do: options
7
8 def accepts_html?({"accept", a}), do: String.contains?(a, "text/html")
9 def accepts_html?({_, _}), do: false
10
11 def call(conn, _) do
12 with true <- Pleroma.Config.get([:instance, :static_fe], false),
13 {_, _} <- Enum.find(conn.req_headers, &accepts_html?/1) do
14 Pleroma.Web.StaticFE.StaticFEController.call(conn, :show)
15 else
16 _ -> conn
17 end
18 end
19 end