diff options
| author | Ben Busby <noreply+git@benbusby.com> | 2021-11-15 20:09:34 -0700 |
|---|---|---|
| committer | Ben Busby <noreply+git@benbusby.com> | 2021-11-15 20:09:34 -0700 |
| commit | d4581797e7a06cf4c89cf03def30e19726f26d11 (patch) | |
| tree | a5bac6c35011d8f384bbb361c2aa7565629f057d /lib | |
| parent | 5904c7cce4d42cf29d775dc39e51183a9be2d82f (diff) | |
| download | farside-d4581797e7a06cf4c89cf03def30e19726f26d11.tar.gz | |
Allow bypassing app router with `FARSIDE_NO_ROUTER`
Setting the aforementioned env var skips creation of the app router,
which is useful for running update.exs when the main app is already
running (otherwise there's a port conflict).
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/farside/application.ex | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/farside/application.ex b/lib/farside/application.ex index fd199e1..d1c5e25 100644 --- a/lib/farside/application.ex +++ b/lib/farside/application.ex @@ -1,4 +1,5 @@ defmodule Farside.Application do + @farside_port Application.fetch_env!(:farside, :port) @redis_conn Application.fetch_env!(:farside, :redis_conn) @moduledoc false @@ -6,12 +7,22 @@ defmodule Farside.Application do @impl true def start(_type, _args) do - children = [ - Plug.Cowboy.child_spec(scheme: :http, plug: Farside.Router, options: [port: 4001]), - {Redix, {@redis_conn, [name: :redix]}}, + plug_children = [ + Plug.Cowboy.child_spec( + scheme: :http, + plug: Farside.Router, + options: [ + port: @farside_port + ] + ), {PlugAttack.Storage.Ets, name: Farside.Throttle.Storage, clean_period: 60_000} ] + children = [ + {Redix, {@redis_conn, [name: :redix]}} | + System.get_env("FARSIDE_NO_ROUTER") && [] || plug_children + ] + opts = [strategy: :one_for_one, name: Farside.Supervisor] Supervisor.start_link(children, opts) end |
