lyokato / riverside

Elixir Library: Simple WebSocket Server Framework
MIT License
88 stars 12 forks source link

Runtime config #51

Closed yurikoval closed 5 years ago

yurikoval commented 5 years ago

Heroku randomly assigns variables like PORT that is needed to run riverside, so it's best to load config during runtime.

This PR will let us use riverside on Heroku if we define config like so:

# config/config.exs
config :otp_app, MyHandler,
  port: ConfigHelper.heroku_port(),
  path: "/websocket",
  max_connections: 10_000,
  max_connection_age: :infinity,
  idle_timeout: 300_000,
  reuse_port: false,
  show_debug_logs: false,
  transmission_limit: [
    capacity: 50,
    duration: 2000
  ]

and we have a helper like so:

defmodule ConfigHelper do
  def heroku_port, do: (System.get_env("PORT") || "3010") |> to_integer
  defp to_integer(a) do
    {port, _} = Integer.parse(a)
    port
  end
end
lyokato commented 5 years ago

Thanks,

I understood that runtime-port-configuration is important. not only for Heroku, but also for other container based deployment architectures.

So, I'd like to support runtime-port-configuration.

However, I'd like to avoid loading values (which can be changed by side effect) every time when each configuration field is required.

So, I've tried another way, confex styled configuration. Loading environment variable is done once during launch-time only. https://github.com/lyokato/riverside/pull/52

v1.2.3 is published on hex.pm, including this change and your other PR(removes deprecated warning, thanks!) Could you try this version?

yurikoval commented 5 years ago

Hey, thanks for your input. Just tried #52 with Heroku and to works great. It's definitely better to do it that way. Thanks!