From ad2da6cdc64a57b9cd938522ee7dc16d06526a9b Mon Sep 17 00:00:00 2001 From: mithereal Date: Sat, 17 Sep 2022 14:34:10 -0700 Subject: [PATCH] add status routes --- README.md | 4 ++++ lib/farside/router.ex | 20 ++++++++++++++++++++ lib/service.ex | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f7771d2..6820201 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/farside/router.ex b/lib/farside/router.ex index f729ebc..9acac24 100644 --- a/lib/farside/router.ex +++ b/lib/farside/router.ex @@ -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) diff --git a/lib/service.ex b/lib/service.ex index e0f84ce..35a3432 100644 --- a/lib/service.ex +++ b/lib/service.ex @@ -1,6 +1,6 @@ defmodule Service do @moduledoc nil - + @derive Jason.Encoder defstruct type: nil, test_url: nil, fallback: nil,