defmodule DummyApiWeb.Version do
import Plug.Conn
@versions Application.get_env(:dummy_api, :versions)
def init(opts), do: opts
def call(conn, opts) do
version = validate_version!(opts[:version])
assign(conn, :version, version)
end
defp validate_version!(provided_version) do
if provided_version in @versions do
provided_version
else
raise "(VersionNotFound) expected any of #{inspect(@versions)}, got #{provided_version}"
end
end
end
And this is my config/config.exs file:
use Mix.Config
config :dummy_api,
versions: [:v1]
...
import_config "#{Mix.env()}.exs"
But for some reason @versions always gets set to nil
You may have to force recompilation of dummy_api_web/version.ex with a mix clean since it looks like it was not recompiled after you changed your config. This article talks about some of the potential drawbacks of module attributes: https://ropig.com/blog/be-careful-when-using-elixirs-module-attributes/
As you sometimes use dummy_app and there is also levi_app in the stack trace, can you please create a minimal project from scratch that shows the problem and push it to GitHub or similar services?