I'm trying to set a library config to point to a file path (a geoip db) in priv
:'
config :geolix, databases: [
%{
id: :city,
adapter: Geolix.Adapter.MMDB2,
source: Application.app_dir(:zipbooks, "priv") |> Path.join("data/GeoLite2-City.mmdb")
}
]
but my
config :zipbooks, …
is in the same file at the top. I get this error:
** (Mix.Config.LoadError) could not load config config/config.exs
** (ArgumentError) unknown application: :zipbooks
I use releases, so I can't hard code the priv
path because the relative location of it will change. I've used Application.app_dir(:zipbooks, "priv")
reliably in the past so I'm wonder how to accomplish this in config.exs
I'm guessing this isn't possible. So what I ended up doing was this:
def start(_type, _args) do
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: ZB.Supervisor]
Application.get_env(:zipbooks, :env)
|> children
|> Supervisor.start_link(opts)
|> after_start
end
defp after_start({:ok, _} = result) do
Geolix.load_database(%{
id: :city,
adapter: Geolix.Adapter.MMDB2,
source: Application.app_dir(:zipbooks, "priv") |> Path.join("data/GeoLite2-City.mmdb")
})
result
end
defp after_start(result), do: result
I ended up using the following in my config.ex. Seems to work fine for me in dev builds so far.
config :zippy, :assets_folder, Path.join(Path.dirname(__DIR__), "priv/assets")
Found this solution over here: https://groups.google.com/forum/#!topic/phoenix-talk/teaQI8fzHuQ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With