aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--config/config.exs4
-rw-r--r--docs/configuration/cheatsheet.md10
-rw-r--r--lib/pleroma/plugs/frontend_static.ex1
-rw-r--r--lib/pleroma/web/endpoint.ex14
-rw-r--r--test/plugs/frontend_static_test.exs27
6 files changed, 51 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7d5256600..fb782e82c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
+- Frontends: Add configurable frontends for primary and admin fe.
- Chats: Added `accepts_chat_messages` field to user, exposed in APIs and federation.
- Chats: Added support for federated chats. For details, see the docs.
- ActivityPub: Added support for existing AP ids for instances migrated from Mastodon.
diff --git a/config/config.exs b/config/config.exs
index 4b91a58b7..0c9685c4c 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -655,7 +655,9 @@ config :pleroma, :static_fe, enabled: false
# With no frontend configuration, the bundled files from the `static` directory will
# be used.
#
-# config :pleroma, :frontends, primary: %{"name" => "pleroma", "ref" => "develop"}
+# config :pleroma, :frontends,
+# primary: %{"name" => "pleroma", "ref" => "develop"},
+# admin: %{"name" => "admin", "ref" => "stable"}
config :pleroma, :web_cache_ttl,
activity_pub: nil,
diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md
index d6a9276ee..9aa1e2f2c 100644
--- a/docs/configuration/cheatsheet.md
+++ b/docs/configuration/cheatsheet.md
@@ -1053,11 +1053,11 @@ Control favicons for instances.
Frontends in Pleroma are swappable - you can specify which one to use here.
-For now, you can set a frontend with the key `primary` and the options of `name` and `ref`. This will then make Pleroma serve the frontend from a folder constructed by concatenating the instance static path, `frontends` and the name and ref.
+You can set a frontends for the key `primary` and `admin` and the options of `name` and `ref`. This will then make Pleroma serve the frontend from a folder constructed by concatenating the instance static path, `frontends` and the name and ref.
-The key `primary` refers to the frontend that will be served by default for general requests. In the future, other frontends like the admin frontend will also be configurable here.
+The key `primary` refers to the frontend that will be served by default for general requests. The key `admin` refers to the frontend that will be served at the `/pleroma/admin` path.
-If you don't set anything here, the bundled frontend will be used.
+If you don't set anything here, the bundled frontends will be used.
Example:
@@ -1066,6 +1066,10 @@ config :pleroma, :frontends,
primary: %{
"name" => "pleroma",
"ref" => "stable"
+ },
+ admin: %{
+ "name" => "admin",
+ "ref" => "develop"
}
```
diff --git a/lib/pleroma/plugs/frontend_static.ex b/lib/pleroma/plugs/frontend_static.ex
index f549ca75f..11a0d5382 100644
--- a/lib/pleroma/plugs/frontend_static.ex
+++ b/lib/pleroma/plugs/frontend_static.ex
@@ -30,6 +30,7 @@ defmodule Pleroma.Plugs.FrontendStatic do
opts
|> Keyword.put(:from, "__unconfigured_frontend_static_plug")
|> Plug.Static.init()
+ |> Map.put(:frontend_type, opts[:frontend_type])
end
def call(conn, opts) do
diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex
index 527fb288d..8b153763d 100644
--- a/lib/pleroma/web/endpoint.ex
+++ b/lib/pleroma/web/endpoint.ex
@@ -39,6 +39,18 @@ defmodule Pleroma.Web.Endpoint do
}
)
+ plug(Plug.Static.IndexHtml, at: "/pleroma/admin/")
+
+ plug(Pleroma.Plugs.FrontendStatic,
+ at: "/pleroma/admin",
+ frontend_type: :admin,
+ gzip: true,
+ cache_control_for_etags: @static_cache_control,
+ headers: %{
+ "cache-control" => @static_cache_control
+ }
+ )
+
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phoenix.digest
@@ -56,8 +68,6 @@ defmodule Pleroma.Web.Endpoint do
}
)
- plug(Plug.Static.IndexHtml, at: "/pleroma/admin/")
-
plug(Plug.Static,
at: "/pleroma/admin/",
from: {:pleroma, "priv/static/adminfe/"}
diff --git a/test/plugs/frontend_static_test.exs b/test/plugs/frontend_static_test.exs
index d11d91d78..6f4923048 100644
--- a/test/plugs/frontend_static_test.exs
+++ b/test/plugs/frontend_static_test.exs
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FrontendStaticPlugTest do
+ alias Pleroma.Plugs.FrontendStatic
use Pleroma.Web.ConnCase
@dir "test/tmp/instance_static"
@@ -14,6 +15,18 @@ defmodule Pleroma.Web.FrontendStaticPlugTest do
setup do: clear_config([:instance, :static_dir], @dir)
+ test "init will give a static plug config + the frontend type" do
+ opts =
+ [
+ at: "/admin",
+ frontend_type: :admin
+ ]
+ |> FrontendStatic.init()
+
+ assert opts[:at] == ["admin"]
+ assert opts[:frontend_type] == :admin
+ end
+
test "overrides existing static files", %{conn: conn} do
name = "pelmora"
ref = "uguu"
@@ -27,4 +40,18 @@ defmodule Pleroma.Web.FrontendStaticPlugTest do
index = get(conn, "/")
assert html_response(index, 200) == "from frontend plug"
end
+
+ test "overrides existing static files for the `pleroma/admin` path", %{conn: conn} do
+ name = "pelmora"
+ ref = "uguu"
+
+ clear_config([:frontends, :admin], %{"name" => name, "ref" => ref})
+ path = "#{@dir}/frontends/#{name}/#{ref}"
+
+ File.mkdir_p!(path)
+ File.write!("#{path}/index.html", "from frontend plug")
+
+ index = get(conn, "/pleroma/admin/")
+ assert html_response(index, 200) == "from frontend plug"
+ end
end