add swagger UI
This commit is contained in:
parent
8215434c65
commit
5f3cfb656a
9 changed files with 110 additions and 39 deletions
|
@ -719,6 +719,11 @@
|
|||
|
||||
config :pleroma, :frontends,
|
||||
primary: %{"name" => "pleroma-fe", "ref" => "develop"},
|
||||
swagger: %{
|
||||
"name" => "swagger-ui",
|
||||
"ref" => "stable",
|
||||
"enabled" => false
|
||||
},
|
||||
available: %{
|
||||
"pleroma-fe" => %{
|
||||
"name" => "pleroma-fe",
|
||||
|
@ -748,6 +753,14 @@
|
|||
"https://gitlab.com/soapbox-pub/soapbox-fe/-/jobs/artifacts/${ref}/download?job=build-production",
|
||||
"ref" => "v1.0.0",
|
||||
"build_dir" => "static"
|
||||
},
|
||||
# For developers - enables a swagger frontend to view the openapi spec
|
||||
"swagger-ui" => %{
|
||||
"name" => "swagger-ui",
|
||||
"git" => "https://github.com/swagger-api/swagger-ui",
|
||||
"build_url" => "https://akkoma-updates.s3-website.fr-par.scw.cloud/frontend/swagger-ui.zip",
|
||||
"build_dir" => "dist",
|
||||
"ref" => "stable"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3089,6 +3089,21 @@
|
|||
description: "Admin frontend",
|
||||
children: installed_frontend_options
|
||||
},
|
||||
%{
|
||||
key: :swagger,
|
||||
type: :map,
|
||||
description: "Swagger API reference frontend",
|
||||
children:
|
||||
installed_frontend_options ++
|
||||
[
|
||||
%{
|
||||
key: "enabled",
|
||||
label: "Enabled",
|
||||
type: :boolean,
|
||||
description: "Whether to have this enabled at all"
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :available,
|
||||
type: :map,
|
||||
|
|
|
@ -270,6 +270,33 @@ config :pleroma, :frontend_configurations,
|
|||
|
||||
These settings **need to be complete**, they will override the defaults.
|
||||
|
||||
### :frontends
|
||||
|
||||
These settings tell akkoma which frontend files to serve the user.
|
||||
|
||||
See: [Frontend Management](../frontend_management)
|
||||
|
||||
```elixir
|
||||
config :pleroma, :frontends,
|
||||
primary: %{
|
||||
"name" => "pleroma-fe",
|
||||
"ref" => "develop"
|
||||
},
|
||||
admin: %{
|
||||
"name" => "admin-fe",
|
||||
"ref" => "develop"
|
||||
},
|
||||
swagger: %{
|
||||
"name" => "swagger-ui",
|
||||
"ref" => "stable",
|
||||
"enabled" => true
|
||||
}
|
||||
```
|
||||
|
||||
* `:primary` - The frontend that will be served at `/`
|
||||
* `:admin` - The frontend that will be served at `/pleroma/admin`
|
||||
* `:swagger` - Config for developers to act as an API reference to be served at `/akkoma/swaggerui/` (trailing slash _needed_). Disabled by default.
|
||||
|
||||
### :static_fe
|
||||
|
||||
Render profiles and posts using server-generated HTML that is viewable without using JavaScript.
|
||||
|
@ -1088,40 +1115,6 @@ Control favicons for instances.
|
|||
4. C:\TMP on Windows or /tmp on Unix-like operating systems
|
||||
5. as a last resort, the current working directory
|
||||
|
||||
## Frontend management
|
||||
|
||||
Frontends in Akkoma are swappable - you can specify which one to use here.
|
||||
|
||||
You can set a frontends for the key `primary` and `admin` and the options of `name` and `ref`. This will then make Akkoma 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. The key `admin` refers to the frontend that will be served at the `/pleroma/admin` path.
|
||||
|
||||
If you don't set anything here, you will not have _any_ frontend at all.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
config :pleroma, :frontends,
|
||||
primary: %{
|
||||
"name" => "pleroma",
|
||||
"ref" => "stable"
|
||||
},
|
||||
admin: %{
|
||||
"name" => "admin",
|
||||
"ref" => "develop"
|
||||
}
|
||||
```
|
||||
|
||||
This would serve the frontend from the the folder at `$instance_static/frontends/pleroma/stable`. You have to copy the frontend into this folder yourself. You can choose the name and ref any way you like, but they will be used by mix tasks to automate installation in the future, the name referring to the project and the ref referring to a commit.
|
||||
|
||||
Refer to [the frontend CLI task](../../administration/CLI_tasks/frontend) for how to install the frontend's files
|
||||
|
||||
If you wish masto-fe to also be enabled, you will also need to run the install task for `mastodon-fe`. Not doing this will lead to the frontend not working.
|
||||
|
||||
If you choose not to install a frontend for whatever reason, it is recommended that you enable [`:static_fe`](#static_fe) to allow remote users to click "view remote source". Don't bother with this if you've got no unauthenticated access though.
|
||||
|
||||
You can also replace the default "no frontend" page by placing an `index.html` file under your `instance/static/` directory.
|
||||
|
||||
### Theme settings
|
||||
|
||||
Settings to change theme as exposed to the outside world, for software
|
||||
|
|
40
docs/configuration/frontend_management.md
Normal file
40
docs/configuration/frontend_management.md
Normal file
|
@ -0,0 +1,40 @@
|
|||
# Frontend Management
|
||||
|
||||
Frontends in Akkoma are swappable, you can pick which you'd like.
|
||||
|
||||
For a basic setup, you can set a frontends for the key `primary` and `admin` and the options of `name` and `ref`. This will then make Akkoma 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. The key `admin` refers to the frontend that will be served at the `/pleroma/admin` path.
|
||||
|
||||
If you don't set anything here, you will not have _any_ frontend at all.
|
||||
|
||||
Example:
|
||||
|
||||
```elixir
|
||||
config :pleroma, :frontends,
|
||||
primary: %{
|
||||
"name" => "pleroma",
|
||||
"ref" => "stable"
|
||||
},
|
||||
admin: %{
|
||||
"name" => "admin",
|
||||
"ref" => "develop"
|
||||
},
|
||||
dwarves: %{
|
||||
"name" => "diggydiggy",
|
||||
"ref" => "hole"
|
||||
},
|
||||
extra: [
|
||||
%{"subdomain" => "dwarves", "key" => :dwarves}
|
||||
]
|
||||
```
|
||||
|
||||
This would serve the frontend from the the folder at `$instance_static/frontends/pleroma/stable`. You have to copy the frontend into this folder yourself. You can choose the name and ref any way you like, but they will be used by mix tasks to automate installation in the future, the name referring to the project and the ref referring to a commit.
|
||||
|
||||
Refer to [the frontend CLI task](../../administration/CLI_tasks/frontend) for how to install the frontend's files
|
||||
|
||||
If you wish masto-fe to also be enabled, you will also need to run the install task for `mastodon-fe`. Not doing this will lead to the frontend not working.
|
||||
|
||||
If you choose not to install a frontend for whatever reason, it is recommended that you enable [`:static_fe`](#static_fe) to allow remote users to click "view remote source". Don't bother with this if you've got no unauthenticated access though.
|
||||
|
||||
You can also replace the default "no frontend" page by placing an `index.html` file under your `instance/static/` directory.
|
7
lib/akkoma/web/swagger.ex
Normal file
7
lib/akkoma/web/swagger.ex
Normal file
|
@ -0,0 +1,7 @@
|
|||
defmodule Akkoma.Web.Swagger do
|
||||
alias Pleroma.Config
|
||||
|
||||
def ui_enabled? do
|
||||
Config.get([:frontends, :swagger, "enabled"])
|
||||
end
|
||||
end
|
|
@ -66,12 +66,13 @@ defmodule Pleroma.Web.Endpoint do
|
|||
}
|
||||
)
|
||||
|
||||
plug(Plug.Static.IndexHtml, at: "/pleroma/fedife/")
|
||||
plug(Plug.Static.IndexHtml, at: "/akkoma/swaggerui")
|
||||
|
||||
plug(Pleroma.Web.Plugs.FrontendStatic,
|
||||
at: "/pleroma/fedife",
|
||||
frontend_type: :fedife,
|
||||
at: "/akkoma/swaggerui",
|
||||
frontend_type: :swagger,
|
||||
gzip: true,
|
||||
if: &Akkoma.Web.Swagger.ui_enabled?/0,
|
||||
cache_control_for_etags: @static_cache_control,
|
||||
headers: %{
|
||||
"cache-control" => @static_cache_control
|
||||
|
|
|
@ -31,11 +31,13 @@ def init(opts) do
|
|||
|> Keyword.put(:from, "__unconfigured_frontend_static_plug")
|
||||
|> Plug.Static.init()
|
||||
|> Map.put(:frontend_type, opts[:frontend_type])
|
||||
|> Map.put(:if, Keyword.get(opts, :if, fn -> true end))
|
||||
end
|
||||
|
||||
def call(conn, opts) do
|
||||
with false <- api_route?(conn.path_info),
|
||||
false <- invalid_path?(conn.path_info),
|
||||
true <- opts[:if].(),
|
||||
frontend_type <- Map.get(opts, :frontend_type, :primary),
|
||||
path when not is_nil(path) <- file_path("", frontend_type) do
|
||||
call_static(conn, opts, path)
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -194,7 +194,7 @@ defp deps do
|
|||
{:restarter, path: "./restarter"},
|
||||
{:majic, "~> 1.0"},
|
||||
{:eblurhash, "~> 1.2.2"},
|
||||
{:open_api_spex, "~> 3.10"},
|
||||
{:open_api_spex, "~> 3.11"},
|
||||
{:search_parser,
|
||||
git: "https://github.com/FloatingGhost/pleroma-contrib-search-parser.git",
|
||||
ref: "08971a81e68686f9ac465cfb6661d51c5e4e1e7f"},
|
||||
|
|
2
mix.lock
2
mix.lock
|
@ -92,7 +92,7 @@
|
|||
"nimble_pool": {:hex, :nimble_pool, "0.2.6", "91f2f4c357da4c4a0a548286c84a3a28004f68f05609b4534526871a22053cde", [:mix], [], "hexpm", "1c715055095d3f2705c4e236c18b618420a35490da94149ff8b580a2144f653f"},
|
||||
"nodex": {:git, "https://git.pleroma.social/pleroma/nodex", "cb6730f943cfc6aad674c92161be23a8411f15d1", [ref: "cb6730f943cfc6aad674c92161be23a8411f15d1"]},
|
||||
"oban": {:hex, :oban, "2.3.4", "ec7509b9af2524d55f529cb7aee93d36131ae0bf0f37706f65d2fe707f4d9fd8", [:mix], [{:ecto_sql, ">= 3.4.3", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c70ca0434758fd1805422ea4446af5e910ddc697c0c861549c8f0eb0cfbd2fdf"},
|
||||
"open_api_spex": {:hex, :open_api_spex, "3.10.0", "94e9521ad525b3fcf6dc77da7c45f87fdac24756d4de588cb0816b413e7c1844", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.1", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "2dbb2bde3d2b821f06936e8dfaf3284331186556291946d84eeba3750ac28765"},
|
||||
"open_api_spex": {:hex, :open_api_spex, "3.11.0", "e4ea9c00e2891c3195c2df511c49e280e7210272ba0077d8d9975258c70e43c0", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.1 or ~> 4.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "640bd09f6bdd96cc0264213bfa229b0f8b3868df3384311de57e0f3fa22fc3af"},
|
||||
"p1_utils": {:hex, :p1_utils, "1.0.18", "3fe224de5b2e190d730a3c5da9d6e8540c96484cf4b4692921d1e28f0c32b01c", [:rebar3], [], "hexpm", "1fc8773a71a15553b179c986b22fbeead19b28fe486c332d4929700ffeb71f88"},
|
||||
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
|
||||
"pbkdf2_elixir": {:hex, :pbkdf2_elixir, "1.2.1", "9cbe354b58121075bd20eb83076900a3832324b7dd171a6895fab57b6bb2752c", [:mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}], "hexpm", "d3b40a4a4630f0b442f19eca891fcfeeee4c40871936fed2f68e1c4faa30481f"},
|
||||
|
|
Loading…
Reference in a new issue