1 defmodule Pleroma.Plugs.InstanceStatic do
3 This is a shim to call `Plug.Static` but with runtime `from` configuration.
5 Mountpoints are defined directly in the module to avoid calling the configuration for every request including non-static ones.
11 Path.join(Pleroma.Config.get([:instance, :static_dir], "instance/static/"), path)
13 if File.exists?(instance_path) do
16 Path.join(Application.app_dir(:pleroma, "priv/static/"), path)
20 @only ~w(index.html static emoji packs sounds images instance favicon.png)
24 |> Keyword.put(:from, "__unconfigured_instance_static_plug")
25 |> Keyword.put(:at, "/__unconfigured_instance_static_plug")
30 at = Plug.Router.Utils.split("/")
32 def call(conn = %{request_path: "/" <> unquote(only) <> _}, opts) do
37 Pleroma.Config.get([:instance, :static_dir], "instance/static")
46 defp call_static(conn, opts, at, from) do
49 |> Map.put(:from, from)
52 Plug.Static.call(conn, opts)