2019-11-02 02:47:18 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Plugs.StaticFEPlug do
|
2019-11-05 06:02:10 +00:00
|
|
|
import Plug.Conn
|
|
|
|
alias Pleroma.Web.StaticFE.StaticFEController
|
2019-11-02 02:47:18 +00:00
|
|
|
|
2019-11-05 06:02:10 +00:00
|
|
|
def init(options), do: options
|
2019-11-03 20:29:17 +00:00
|
|
|
|
2019-11-02 02:47:18 +00:00
|
|
|
def call(conn, _) do
|
2019-11-05 06:02:10 +00:00
|
|
|
if enabled?() and accepts_html?(conn) do
|
|
|
|
conn
|
|
|
|
|> StaticFEController.call(:show)
|
|
|
|
|> halt()
|
2019-11-03 20:29:17 +00:00
|
|
|
else
|
2019-11-05 06:02:10 +00:00
|
|
|
conn
|
2019-11-02 02:47:18 +00:00
|
|
|
end
|
|
|
|
end
|
2019-11-05 06:02:10 +00:00
|
|
|
|
|
|
|
defp enabled?, do: Pleroma.Config.get([:instance, :static_fe], false)
|
|
|
|
|
|
|
|
defp accepts_html?(conn) do
|
|
|
|
conn |> get_req_header("accept") |> List.first() |> String.contains?("text/html")
|
|
|
|
end
|
2019-11-02 02:47:18 +00:00
|
|
|
end
|