summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Felder <feld@feld.me>2021-02-25 09:23:10 -0600
committerMark Felder <feld@feld.me>2021-02-25 09:23:10 -0600
commit6b87dfad5de161cf2bef43d02ff89debcee84dd3 (patch)
treec581ca985935d911d4da8c172b1bf50c20a08885
parent8ad16137173cc57e6947caf1860c3073c0cfdf04 (diff)
Filter out MIX_ENV from route list and add a test
-rw-r--r--lib/pleroma/web.ex8
-rw-r--r--test/pleroma/web/plugs/frontend_static_plug_test.exs28
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/pleroma/web.ex b/lib/pleroma/web.ex
index a638bb198..0a4c98e47 100644
--- a/lib/pleroma/web.ex
+++ b/lib/pleroma/web.ex
@@ -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)
diff --git a/test/pleroma/web/plugs/frontend_static_plug_test.exs b/test/pleroma/web/plugs/frontend_static_plug_test.exs
index c8cfc967c..9d59d3f8e 100644
--- a/test/pleroma/web/plugs/frontend_static_plug_test.exs
+++ b/test/pleroma/web/plugs/frontend_static_plug_test.exs
@@ -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