Home > OS >  secure of phoenix Plug.Session set value on runtime
secure of phoenix Plug.Session set value on runtime

Time:11-02

I want to set value of secure on runtime. But it is set value on compile time. I don’t know how to do that. My env is elixir 12, erlang 24 Plz help me

plug Plug.Session,
    store: :cookie,
    key: "_key",
    signing_salt: "KahwH24",
    max_age: 60 * 60,
    secure: System.get_env("PLUG_SESSION_SECURE", "true") == "true"

CodePudding user response:

I am assuming you are facing the issue on your production environment.

If you are using Elixir releases and Phoenix 1.6 for deployment, you can place this code inside config/runtime.exs. Phoenix picks up these configurations at runtime.

If you are using Distillery, you can use config providers which help configure the app at runtime.

CodePudding user response:

With a few exceptions, it turns out that most things in an Elixir app can be configured during runtime. The secret is to use the config/runtime.exs file. I have found that using ONLY the config/config.exs for compile-time configurations and config/runtime.exs for runtime configurations aligns better with how I think about my code and its environment, and it fits in nicely with the recommendations of the 12-Factor App

See article re runtime Configuration in Elixir using Dotenvy

  • Related