Filter out MIX_ENV from route list and add a test

This commit is contained in:
Mark Felder 2021-02-25 09:23:10 -06:00
parent 8ad1613717
commit 6b87dfad5d
2 changed files with 35 additions and 1 deletions

View File

@ -28,6 +28,8 @@ defmodule Pleroma.Web do
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
alias Pleroma.Web.Plugs.PlugHelper alias Pleroma.Web.Plugs.PlugHelper
@mix_env Mix.env()
def controller do def controller do
quote do quote do
use Phoenix.Controller, namespace: Pleroma.Web use Phoenix.Controller, namespace: Pleroma.Web
@ -236,7 +238,11 @@ def base_url do
def get_api_routes do def get_api_routes do
Pleroma.Web.Router.__routes__() 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 -> |> Enum.map(fn r ->
r.path r.path
|> String.split("/", trim: true) |> String.split("/", trim: true)

View File

@ -74,4 +74,32 @@ test "exclude invalid path", %{conn: conn} do
assert %Plug.Conn{status: :success} = get(conn, url) assert %Plug.Conn{status: :success} = get(conn, url)
end end
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 end