mirror of
https://github.com/benbusby/farside.git
synced 2025-06-06 17:36:37 +00:00
Format with mix format
This commit is contained in:
parent
76faebd234
commit
2ea805bd88
2 changed files with 24 additions and 19 deletions
|
@ -3,8 +3,8 @@ defmodule PrivacyRevolver.Router do
|
||||||
|
|
||||||
use Plug.Router
|
use Plug.Router
|
||||||
|
|
||||||
plug :match
|
plug(:match)
|
||||||
plug :dispatch
|
plug(:dispatch)
|
||||||
|
|
||||||
get "/" do
|
get "/" do
|
||||||
send_resp(conn, 200, "")
|
send_resp(conn, 200, "")
|
||||||
|
@ -18,27 +18,32 @@ defmodule PrivacyRevolver.Router do
|
||||||
|
|
||||||
get "/:service/*glob" do
|
get "/:service/*glob" do
|
||||||
path = Enum.join(glob, "/")
|
path = Enum.join(glob, "/")
|
||||||
{:ok, instances} = Redix.command(
|
|
||||||
|
{:ok, instances} =
|
||||||
|
Redix.command(
|
||||||
:redix,
|
:redix,
|
||||||
["LRANGE", service, "0", "-1"]
|
["LRANGE", service, "0", "-1"]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Either pick a random available instance,
|
# Either pick a random available instance,
|
||||||
# or fall back to the default one
|
# or fall back to the default one
|
||||||
instance = if Enum.count(instances) > 0 do
|
instance =
|
||||||
|
if Enum.count(instances) > 0 do
|
||||||
Enum.random(instances)
|
Enum.random(instances)
|
||||||
else
|
else
|
||||||
{:ok, result} = Redix.command(
|
{:ok, result} =
|
||||||
|
Redix.command(
|
||||||
:redix,
|
:redix,
|
||||||
["GET", "#{service}#{@fallback_str}"]
|
["GET", "#{service}#{@fallback_str}"]
|
||||||
)
|
)
|
||||||
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
# Redirect to the available instance
|
# Redirect to the available instance
|
||||||
conn |>
|
conn
|
||||||
Plug.Conn.resp(:found, "") |>
|
|> Plug.Conn.resp(:found, "")
|
||||||
Plug.Conn.put_resp_header(
|
|> Plug.Conn.put_resp_header(
|
||||||
"location",
|
"location",
|
||||||
"#{instance}/#{path}"
|
"#{instance}/#{path}"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue