Phillipp

Phillipp

Configure Plug.Static at runtime

Hey,

is there a way to configure Plug.Static at runtime (right after boot)?

I have a usecase where the location of the files and the desired request path (:from and :at options) is only known after startup.

Marked As Solved

evadne

evadne

This is going to be complicated because Plug.Static uses pattern matching to only match against particular from / at values. I guess you could write a custom plug that makes its decisions dynamically and eat the performance loss.

Also Liked

Phillipp

Phillipp

Performance is not a big deal here. So I might look into building my own version of Plug.Static.

EDIT: Seems like it would be enough to create a wrapper plug that calls Plug.Static.call/2 with the conn and the dynamically created options.

Last Post!

LostKobrakai

LostKobrakai

I’m wondering if you called Plug.Static.init/1 still. The opts for call/2 are not always the same data passed on the plug call.

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement