miquecg
Usage of Mix.env() discouraged in Phoenix router?
Hi!
I’m curious about the usage of Mix.env() in Phoenix router. Bamboo recommends to add a conditional route for :dev environment to see emails that are kept in memory when using Bamboo.LocalAdapter.
# In your Router
defmodule MyApp.Router do
use Phoenix.Router # or use Plug.Router if you're not using Phoenix
if Mix.env == :dev do
# If using Phoenix
forward "/sent_emails", Bamboo.SentEmailViewerPlug
# If using Plug.Router, make sure to add the `to`
forward "/sent_emails", to: Bamboo.SentEmailViewerPlug
end
end
Others have asked similar questions here and the conclusion seems to be that it’s not a bad practice because routes are compiled. But since Mix is a build tool, I’m wondering if this holds true when using releases for example, so it will be a better idea to use Application config values.
Marked As Solved
LostKobrakai
The Mix.env call won’t land in your release, because that if expression is executed when compiling the module to a beam file – a.k.a. when creating the release. Only the resulting beam files are included in the release itself. Therefore it’s not problematic in terms of Mix being not available at runtime.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









