diff options
| author | Ben Busby <contact@benbusby.com> | 2022-07-27 13:50:23 -0600 |
|---|---|---|
| committer | Ben Busby <contact@benbusby.com> | 2022-07-27 13:53:33 -0600 |
| commit | a6dabe8bf308b660f7a26e5d2dc702c69b9b5210 (patch) | |
| tree | 9e5249672a3a2265c576e4ed0dddab04822b9871 /lib | |
| parent | 7045b62ccf3460284fa31cf4e082cb8b7ff3a1de (diff) | |
| download | farside-a6dabe8bf308b660f7a26e5d2dc702c69b9b5210.tar.gz | |
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
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/farside/application.ex | 13 | ||||
| -rw-r--r-- | lib/farside/instances.ex | 4 |
2 files changed, 11 insertions, 6 deletions
diff --git a/lib/farside/application.ex b/lib/farside/application.ex index 9fd6e9d..0ab77ea 100644 --- a/lib/farside/application.ex +++ b/lib/farside/application.ex @@ -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 ] diff --git a/lib/farside/instances.ex b/lib/farside/instances.ex index 625bbb4..f37f306 100644 --- a/lib/farside/instances.ex +++ b/lib/farside/instances.ex @@ -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 |
