1
0
Fork 0
mirror of https://github.com/benbusby/farside.git synced 2025-05-04 17:40:02 +00:00

Refactor project to new name

The name of the project is being refactored from Privacy Revolver to
Farside. The reasoning behind this is:
1. A shorter name is easier to remember
2. It can stand for "FOSS alternative redirecting service" (which I know
doesn't encapsulate all letters from "farside", but it's close enough).

This commit also includes improvements to the update script for
determining how far along the script is.
This commit is contained in:
Ben Busby 2021-11-07 12:29:06 -07:00
parent 06bb8403dd
commit 8042dcad0c
No known key found for this signature in database
GPG key ID: 339B7B7EB5333D14
8 changed files with 45 additions and 30 deletions

51
lib/farside/router.ex Normal file
View file

@ -0,0 +1,51 @@
defmodule Farside.Router do
@fallback_str Application.fetch_env!(:farside, :fallback_str)
use Plug.Router
plug(:match)
plug(:dispatch)
get "/" do
send_resp(conn, 200, "")
end
get "/ping" do
# Useful for app healthcheck
{:ok, resp} = Redix.command(:redix, ["PING"])
send_resp(conn, 200, resp)
end
get "/:service/*glob" do
path = Enum.join(glob, "/")
{:ok, instances} =
Redix.command(
:redix,
["LRANGE", service, "0", "-1"]
)
# Either pick a random available instance,
# or fall back to the default one
instance =
if Enum.count(instances) > 0 do
Enum.random(instances)
else
{:ok, result} =
Redix.command(
:redix,
["GET", "#{service}#{@fallback_str}"]
)
result
end
# Redirect to the available instance
conn
|> Plug.Conn.resp(:found, "")
|> Plug.Conn.put_resp_header(
"location",
"#{instance}/#{path}"
)
end
end