logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 6b87dfad5de161cf2bef43d02ff89debcee84dd3
parent 8ad16137173cc57e6947caf1860c3073c0cfdf04
Author: Mark Felder <feld@feld.me>
Date:   Thu, 25 Feb 2021 09:23:10 -0600

Filter out MIX_ENV from route list and add a test

Diffstat:

Mlib/pleroma/web.ex8+++++++-
Mtest/pleroma/web/plugs/frontend_static_plug_test.exs28++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)

diff --git 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 @@ -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