If anyone encounters the same issue in the future, here’s how I resolved it:
I moved the environment variable fetching logic to a helper module, which fixed the problem.
plug CORSPlug, origin: &MyAppWeb.Config.cors_origins/1
Here’s the helper module:
defmodule MyAppWeb.Config do
def cors_origins, do: Application.get_env(:my_app, :cors_origins)
end
Note: Ensure you use the capture operator (&) when calling the function in the plug. Calling it without the capture operator will not work—I made this mistake and spent an entire day debugging it.
I hope this helps anyone facing a similar issue!






















