Make conn values and services path configurable at runtime
Connection values (such as redis server port and the port to run farside on) as well as the services json file to use can now be set via environment variables: FARSIDE_PORT sets the port for Farside to run on FARSIDE_REDIS_PORT sets the redis server port for Farside to use FARSIDE_SERVICES_JSON sets the services json file for Farside to use This partially addresses the move towards de-listing Cloudflare instances by default by allowing different services json files to be used with different redis servers. See #43
This commit is contained in:
parent
7045b62ccf
commit
a6dabe8bf3
6 changed files with 24 additions and 13 deletions
|
@ -63,8 +63,8 @@ Farside's routing is very minimal, with only the following routes:
|
|||
particular service with the specified path
|
||||
- Ex: `/libreddit/r/popular` would navigate to `<libreddit instance
|
||||
URL>/r/popular`
|
||||
- If the service provided is actually a URL to a "parent" service
|
||||
(i.e. "youtube.com" instead of "piped" or "invidious"), Farside
|
||||
- If the service provided is actually a URL to a "parent" service
|
||||
(i.e. "youtube.com" instead of "piped" or "invidious"), Farside
|
||||
will determine the correct frontend to use for the specified URL.
|
||||
- Note that a path is not required. `/libreddit` for example will still
|
||||
redirect the user to a working libreddit instance
|
||||
|
@ -108,3 +108,6 @@ request per second per IP.
|
|||
| Name | Purpose |
|
||||
| -- | -- |
|
||||
| FARSIDE_TEST | If enabled, bypasses the instance availability check and adds all instances to the pool. |
|
||||
| FARSIDE_PORT | The port to run Farside on (default: `4001`) |
|
||||
| FARSIDE_REDIS_PORT | The Redis server port to use (default: `6379`, same as the default for Redis) |
|
||||
| FARSIDE_SERVICES_JSON | The "services" JSON file to use for selecting instances (default: `services.json`) |
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import Config
|
||||
|
||||
config :farside,
|
||||
port: 4001,
|
||||
redis_conn: "redis://localhost:6379",
|
||||
update_file: ".update-results",
|
||||
service_prefix: "service-",
|
||||
fallback_suffix: "-fallback",
|
||||
previous_suffix: "-previous",
|
||||
services_json: "services.json",
|
||||
index: "index.eex",
|
||||
route: "route.eex",
|
||||
headers: [
|
||||
|
|
6
config/runtime.exs
Normal file
6
config/runtime.exs
Normal file
|
@ -0,0 +1,6 @@
|
|||
import Config
|
||||
|
||||
config :farside,
|
||||
port: System.get_env("FARSIDE_PORT", "4001"),
|
||||
redis_conn: "redis://localhost:#{System.get_env("FARSIDE_REDIS_PORT", "6379")}",
|
||||
services_json: System.get_env("FARSIDE_SERVICES_JSON", "services.json")
|
|
@ -1,22 +1,27 @@
|
|||
defmodule Farside.Application do
|
||||
@farside_port Application.fetch_env!(:farside, :port)
|
||||
@redis_conn Application.fetch_env!(:farside, :redis_conn)
|
||||
#@farside_port Application.fetch_env!(:farside, :port)
|
||||
#@redis_conn Application.fetch_env!(:farside, :redis_conn)
|
||||
@moduledoc false
|
||||
|
||||
use Application
|
||||
|
||||
@impl true
|
||||
def start(_type, _args) do
|
||||
redis_conn = Application.fetch_env!(:farside, :redis_conn)
|
||||
farside_port = Application.fetch_env!(:farside, :port)
|
||||
IO.puts "Runing on http://localhost:#{farside_port}"
|
||||
IO.puts "Redis conn: #{redis_conn}"
|
||||
|
||||
children = [
|
||||
Plug.Cowboy.child_spec(
|
||||
scheme: :http,
|
||||
plug: Farside.Router,
|
||||
options: [
|
||||
port: @farside_port
|
||||
port: String.to_integer(farside_port)
|
||||
]
|
||||
),
|
||||
{PlugAttack.Storage.Ets, name: Farside.Throttle.Storage, clean_period: 60_000},
|
||||
{Redix, {@redis_conn, [name: :redix]}},
|
||||
{Redix, {redis_conn, [name: :redix]}},
|
||||
Farside.Scheduler,
|
||||
Farside.Server
|
||||
]
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
defmodule Farside.Instances do
|
||||
@fallback_suffix Application.fetch_env!(:farside, :fallback_suffix)
|
||||
@update_file Application.fetch_env!(:farside, :update_file)
|
||||
@services_json Application.fetch_env!(:farside, :services_json)
|
||||
@service_prefix Application.fetch_env!(:farside, :service_prefix)
|
||||
@headers Application.fetch_env!(:farside, :headers)
|
||||
@queries Application.fetch_env!(:farside, :queries)
|
||||
|
@ -42,7 +41,8 @@ defmodule Farside.Instances do
|
|||
end
|
||||
|
||||
def update() do
|
||||
{:ok, file} = File.read(@services_json)
|
||||
services_json = Application.fetch_env!(:farside, :services_json)
|
||||
{:ok, file} = File.read(services_json)
|
||||
{:ok, json} = Jason.decode(file)
|
||||
|
||||
# Loop through all instances and check each for availability
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
defmodule FarsideTest do
|
||||
@services_json Application.fetch_env!(:farside, :services_json)
|
||||
|
||||
use ExUnit.Case
|
||||
use Plug.Test
|
||||
|
@ -49,7 +48,8 @@ defmodule FarsideTest do
|
|||
end
|
||||
|
||||
test "/:service" do
|
||||
{:ok, file} = File.read(@services_json)
|
||||
services_json = Application.fetch_env!(:farside, :services_json)
|
||||
{:ok, file} = File.read(services_json)
|
||||
{:ok, service_list} = Jason.decode(file)
|
||||
|
||||
service_names =
|
||||
|
|
Loading…
Add table
Reference in a new issue