Filter out MIX_ENV from route list and add a test
authorMark Felder <feld@feld.me>
Thu, 25 Feb 2021 15:23:10 +0000 (09:23 -0600)
committerMark Felder <feld@feld.me>
Thu, 25 Feb 2021 15:23:10 +0000 (09:23 -0600)
lib/pleroma/web.ex
test/pleroma/web/plugs/frontend_static_plug_test.exs

index a638bb1983d5cebf639871061c38a1de82188284..0a4c98e4778c4f59d1f4249b7e8590943b94bdc5 100644 (file)
@@ -28,6 +28,8 @@ defmodule Pleroma.Web do
   alias Pleroma.Web.Plugs.OAuthScopesPlug
   alias Pleroma.Web.Plugs.PlugHelper
 
+  @mix_env Mix.env()
+
   def controller do
     quote do
       use Phoenix.Controller, namespace: Pleroma.Web
@@ -236,7 +238,11 @@ defmodule Pleroma.Web do
 
   def get_api_routes do
     Pleroma.Web.Router.__routes__()
-    |> Enum.reject(fn r -> r.plug == Pleroma.Web.Fallback.RedirectController end)
+    |> Enum.reject(fn
+      r ->
+        r.plug == Pleroma.Web.Fallback.RedirectController or
+          String.starts_with?(r.path, "/#{@mix_env}")
+    end)
     |> Enum.map(fn r ->
       r.path
       |> String.split("/", trim: true)
index c8cfc967c1db2344022ee8679b8e83b2e32fbb0f..9d59d3f8ea8ee3d30e212d212cfae91776fd144b 100644 (file)
@@ -74,4 +74,32 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
       assert %Plug.Conn{status: :success} = get(conn, url)
     end
   end
+
+  test "api routes are detected correctly" do
+    expected_routes = [
+      "api",
+      "main",
+      "ostatus_subscribe",
+      "oauth",
+      "objects",
+      "activities",
+      "notice",
+      "users",
+      "tags",
+      "mailer",
+      "inbox",
+      "relay",
+      "internal",
+      ".well-known",
+      "nodeinfo",
+      "web",
+      "auth",
+      "embed",
+      "proxy",
+      "user_exists",
+      "check_password"
+    ]
+
+    assert expected_routes == Pleroma.Web.get_api_routes()
+  end
 end