Skip to content

Instantly share code, notes, and snippets.

@alanpeabody
Created June 30, 2015 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alanpeabody/b507575415e22a4a0ea3 to your computer and use it in GitHub Desktop.
Save alanpeabody/b507575415e22a4a0ea3 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