add status routes

This commit is contained in:
mithereal 2022-09-17 14:34:10 -07:00
parent d5c3ec736c
commit ad2da6cdc6
3 changed files with 25 additions and 1 deletions

View File

@ -168,6 +168,10 @@ Farside's routing is very minimal, with only the following routes:
jumping between instances by navigating back.
- Ex: `/_/nitter` -> nitter instance A -> (navigate back one page) -> nitter
instance B -> ...
- `/status`
- json of the instance data
- `/backup`
- download json of the instance data
- *Note: Uses Javascript to preserve the page in history*
When a service is requested with the `/:service/...` endpoint, Farside requests

View File

@ -29,6 +29,26 @@ defmodule Farside.Router do
send_resp(conn, 200, resp)
end
get "/backup" do
resp = Jason.encode!(Farside.get_services_map())
conn =
conn
|> put_resp_content_type("application/json")
|> put_resp_header("content-disposition", "attachment; filename=farside.json")
|> Plug.Conn.send_resp(:ok, resp)
send_resp(conn, 200, resp)
end
get "/status" do
resp = Jason.encode!(Farside.get_services_map())
conn = conn |> merge_resp_headers([{"content-type", "application/json"}])
send_resp(conn, 200, resp)
end
get "/_/:service/*glob" do
r_path = String.slice(conn.request_path, 2..-1)

View File

@ -1,6 +1,6 @@
defmodule Service do
@moduledoc nil
@derive Jason.Encoder
defstruct type: nil,
test_url: nil,
fallback: nil,