From 932f3bbcab9be82aafb487d7890fde83b2210a7b Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Thu, 27 Jan 2022 11:57:41 -0700 Subject: Preserve redirect with `/_/` path prefix (#13) This adds a straightforward way of preserving Farside's redirecting behavior in the user's browser history. That way if an instance becomes unavailable between the 5 min scans, the user can opt to navigate back one page and be taken to a new instance. This is accomplished using a single line of JS, and could potentially work as the default behavior of Farside (with the current default behavior requiring a path prefix instead). This should be revisited down the road when more people are using this service. --- lib/farside/router.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib') diff --git a/lib/farside/router.ex b/lib/farside/router.ex index e74f29e..2f0216c 100644 --- a/lib/farside/router.ex +++ b/lib/farside/router.ex @@ -1,5 +1,6 @@ defmodule Farside.Router do @index Application.fetch_env!(:farside, :index) + @route Application.fetch_env!(:farside, :route) use Plug.Router @@ -24,6 +25,19 @@ defmodule Farside.Router do send_resp(conn, 200, resp) end + get "/_/:service/*glob" do + r_path = String.slice(conn.request_path, 2..-1) + + resp = + EEx.eval_file( + @route, + service: service, + instance_url: r_path + ) + + send_resp(conn, 200, resp) + end + get "/:service/*glob" do path = Enum.join(glob, "/") instance = Farside.pick_instance(service) -- cgit v1.2.3