summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Busby <contact@benbusby.com>2022-06-13 10:20:39 -0600
committerBen Busby <contact@benbusby.com>2022-06-13 10:20:39 -0600
commit6210ed56e7bcb6bdbc5cd640001874cf0926f136 (patch)
tree541d992ee4fd914a0f97fc02362f397d77835196
parent213658ae6c68e192d3a5c5f24943b4753f954a01 (diff)
downloadfarside-6210ed56e7bcb6bdbc5cd640001874cf0926f136.tar.gz
Include query params for all `/_/` prefixed links
Query params were not included when using the "/_/" prefix for farside links. This extracts the logic for parsing query params into a function that is then used for both /_/ and non-/_/ links.
-rw-r--r--lib/farside/router.ex24
-rw-r--r--route.eex4
2 files changed, 14 insertions, 14 deletions
diff --git a/lib/farside/router.ex b/lib/farside/router.ex
index e2902f6..85994bc 100644
--- a/lib/farside/router.ex
+++ b/lib/farside/router.ex
@@ -8,6 +8,16 @@ defmodule Farside.Router do
plug(:match)
plug(:dispatch)
+ def get_query_params(conn) do
+ cond do
+ String.length(conn.query_string) > 0 ->
+ "?#{conn.query_string}"
+
+ true ->
+ ""
+ end
+ end
+
get "/" do
resp =
EEx.eval_file(
@@ -31,8 +41,7 @@ defmodule Farside.Router do
resp =
EEx.eval_file(
@route,
- service: service,
- instance_url: r_path
+ instance_url: "#{r_path}#{get_query_params(conn)}"
)
send_resp(conn, 200, resp)
@@ -62,21 +71,12 @@ defmodule Farside.Router do
|> Farside.pick_instance
end
- params =
- cond do
- String.length(conn.query_string) > 0 ->
- "?#{conn.query_string}"
-
- true ->
- ""
- end
-
# Redirect to the available instance
conn
|> Plug.Conn.resp(:found, "")
|> Plug.Conn.put_resp_header(
"location",
- "#{instance}/#{path}#{params}"
+ "#{instance}/#{path}#{get_query_params(conn)}"
)
end
end
diff --git a/route.eex b/route.eex
index a06a265..55538c7 100644
--- a/route.eex
+++ b/route.eex
@@ -1,10 +1,10 @@
<head>
- <title>Farside Redirect - <%= service %></title>
+ <title>Farside Redirect</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...
+ <span>Redirecting to <%= instance_url %>...</span>
</body>