summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--README.md7
-rw-r--r--config/config.exs1
-rw-r--r--lib/farside/router.ex14
-rw-r--r--route.eex10
5 files changed, 34 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 0126d78..87fe868 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,5 @@ erl_crash.dump
# Ignore results from update script
.update-result*
+
+*.rdb
diff --git a/README.md b/README.md
index 2c0bd9f..8ecd3d2 100644
--- a/README.md
+++ b/README.md
@@ -55,6 +55,13 @@ Farside's routing is very minimal, with only the following routes:
URL>/r/popular`
- Note that a path is not required. `/libreddit` for example will still
redirect the user to a working libreddit instance
+- `/_/:service/*glob`
+ - Achieves the same redirect as the main `/:service/*glob` endpoint, but
+ preserves a short landing page in the browser's history to allow quickly
+ jumping between instances by navigating back.
+ - Ex: `/_/nitter` -> nitter instance A -> (navigate back one page) -> nitter
+ instance B -> ...
+ - *Note: Uses Javascript to preserve the page in history*
When a service is requested with the `/:service/...` endpoint, Farside requests
the list of working instances from Redis and returns a random one from the list
diff --git a/config/config.exs b/config/config.exs
index 1c393cd..982990c 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -9,6 +9,7 @@ config :farside,
previous_suffix: "-previous",
services_json: "services.json",
index: "index.eex",
+ route: "route.eex",
headers: [
{"User-Agent", "Mozilla/5.0 (Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0"},
{"Accept", "text/html"},
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)
diff --git a/route.eex b/route.eex
new file mode 100644
index 0000000..a06a265
--- /dev/null
+++ b/route.eex
@@ -0,0 +1,10 @@
+<head>
+ <title>Farside Redirect - <%= service %></title>
+ <meta http-equiv="refresh" content="1; url=<%= instance_url %>">
+ <script>
+ history.pushState({page: 1}, "Farside Redirect");
+ </script>
+</head>
+<body>
+ <span>Redirecting to <%= service %> instance...
+</body>