Merge remote-tracking branch 'pleroma/develop' into errorview-json-fix
[akkoma] / lib / pleroma / web / plugs / frontend_static.ex
index 03fd510431e882ab2c17bcb3cd01560d6dd687b1..ebe7eaf86bbdac1b55e58c36a9532bc8a2d30d0a 100644 (file)
@@ -10,8 +10,6 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
   """
   @behaviour Plug
 
-  @api_routes Pleroma.Web.get_api_routes()
-
   def file_path(path, frontend_type \\ :primary) do
     if configuration = Pleroma.Config.get([:frontends, frontend_type]) do
       instance_static_path = Pleroma.Config.get([:instance, :static_dir], "instance/static")
@@ -55,11 +53,12 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
   defp invalid_path?([h | t], match), do: String.contains?(h, match) or invalid_path?(t)
   defp invalid_path?([], _match), do: false
 
-  defp api_route?(list) when is_list(list) and length(list) > 0 do
-    List.first(list) in @api_routes
-  end
+  defp api_route?([]), do: false
 
-  defp api_route?(_), do: false
+  defp api_route?([h | t]) do
+    api_routes = Pleroma.Web.Router.get_api_routes()
+    if h in api_routes, do: true, else: api_route?(t)
+  end
 
   defp call_static(conn, opts, from) do
     opts = Map.put(opts, :from, from)