Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dev_code_reload_plug.ex
# Reload/recompile code before each request in development only using Plug & Mix.
# Assumes MyApp.Router is a plug that handles actual routing.
def MyApp.Main do
use Plug.Builder
plug :reload
plug :dispatch
def reload(conn, _opts) do
if Mix.env == :dev, do: Mix.Tasks.Compile.Elixir.run(["--ignore-module-conflict"])
conn
end
def dispatch(conn, opts), do: MyApp.Router.call(conn, opts)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment