1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Plugs.InstanceStatic do
7 This is a shim to call `Plug.Static` but with runtime `from` configuration.
9 Mountpoints are defined directly in the module to avoid calling the configuration for every request including non-static ones.
13 def file_path(path) do
15 Path.join(Pleroma.Config.get([:instance, :static_dir], "instance/static/"), path)
17 if File.exists?(instance_path) do
20 Path.join(Application.app_dir(:pleroma, "priv/static/"), path)
24 @only ~w(index.html static emoji packs sounds images instance favicon.png)
28 |> Keyword.put(:from, "__unconfigured_instance_static_plug")
29 |> Keyword.put(:at, "/__unconfigured_instance_static_plug")
34 at = Plug.Router.Utils.split("/")
36 def call(conn = %{request_path: "/" <> unquote(only) <> _}, opts) do
41 Pleroma.Config.get([:instance, :static_dir], "instance/static")
50 defp call_static(conn, opts, at, from) do
53 |> Map.put(:from, from)
56 Plug.Static.call(conn, opts)