Skip to content

Instantly share code, notes, and snippets.

@susilolab
Forked from alanpeabody/dev_code_reload_plug.ex
Created February 26, 2019 14:58
Show Gist options
  • Save susilolab/ccc8be4cd82a71bb761049a726b0366a to your computer and use it in GitHub Desktop.
Save susilolab/ccc8be4cd82a71bb761049a726b0366a to your computer and use it in GitHub Desktop.
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