Kurisu

Kurisu

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.

Most Liked

LostKobrakai

LostKobrakai

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:

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement