From 6b87dfad5de161cf2bef43d02ff89debcee84dd3 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 25 Feb 2021 09:23:10 -0600 Subject: [PATCH] Filter out MIX_ENV from route list and add a test --- lib/pleroma/web.ex | 8 ++++++- .../web/plugs/frontend_static_plug_test.exs | 28 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) 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