Merge remote-tracking branch 'remotes/origin/develop' into 1560-non-federating-instan...
[akkoma] / lib / pleroma / plugs / static_fe_plug.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Plugs.StaticFEPlug do
6 import Plug.Conn
7 alias Pleroma.Web.StaticFE.StaticFEController
8
9 def init(options), do: options
10
11 def call(conn, _) do
12 if enabled?() and accepts_html?(conn) do
13 conn
14 |> StaticFEController.call(:show)
15 |> halt()
16 else
17 conn
18 end
19 end
20
21 defp enabled?, do: Pleroma.Config.get([:static_fe, :enabled], false)
22
23 defp accepts_html?(conn) do
24 conn
25 |> get_req_header("accept")
26 |> List.first()
27 |> String.contains?("text/html")
28 end
29 end