How to use Release config to set a plug static path in an Endpoint on application start?

Currently here is the way I’m attempting to add the static path to some uploads path in MyApp.Endpoint:

# Uploads path
  plug Plug.Static,
    at: "/",
    from: Application.fetch_env!(:waffle, :storage_dir_prefix),
    gzip: false,
    only: [Application.fetch_env!(:waffle, :storage_dir)]

Then in both config/config.exs and config/releases.exs I have:

# See `Waffle.Storage.Local`
config :waffle,
  storage: Waffle.Storage.Local,
  storage_dir_prefix: System.get_env("LOCAL_STORAGE_PATH"),
  storage_dir: "media"

When assembling the release on my development machine, the application endpoint is compiled to serve uploads files on that machine so I can test it before sending the release to the target (production machine).

The issue is that when starting the app on target machine, the endpoint tries to serve uploads files from dev machine path, even if the release config set new path for the purpose. When uploading files on the target, I can see that Waffle use the release config to store the files to the right place, but it is the endpoint that is not using that config.

I tried to call inside the endpoint a function defined in MyApp.Application that return uploads path (to ensure runtime config is prioritized over compile time config), but it can not help either.

Thank you for any guidance on this.

Plug options are set at compile time, therefore you can’t override them like that using releases.exs. If you need to change those settings at runtime see the following example for Plug.Session: