Debugger plug development

Hi everyone!
I would like to make a small edit to https://github.com/elixir-plug/plug, so I cloned the repo locally, edited the debugger template and now I would like to see what it looks like.

I cannot find how to run a development server or something, to load my edited plug! :slight_smile: It seems that I am missing something, so any help would be appreciated!

1 Like

I think the example shown for the Debugger module at the top of its docs might be helpful: https://github.com/elixir-plug/plug/blob/master/lib/plug/debugger.ex

Couple that with the Hello World example from plug’s readme and I reckon you could get something spun up quickly.

I’m on my phone atm and so I can’t provide you a code solution, sorry!

1 Like

Thank you for your response, @radar !
Unfortunately, the example requires to add plug_cowboy to dependencies. When I do so, I get an error like:

Error while loading project :plug at /home/mariosant/Projects/plug/deps/plug
** (Mix) Trying to load Plug.MixProject from "/home/mariosant/Projects/plug/deps/plug/mix.exs" but another project with the same name was already defined at "/home/mariosant/Projects/plug/mix.exs"

I am wondering, what is the development process of this project.

1 Like

Looks like you’ve named your project the same name. Try “mix new plug_example” instead.

1 Like

Hey, thanks for your response @radar!
I think I was not clear. I have cloned the plug (yeah, but I the official one) repo locally and I am preparing a pr with some edits on the debugger plug.
How can I preview my edits? :joy:

@mariosant The easiest way to preview your changes is to do something like:

mix new plug_example --sup

Then change plug_example/mix.exs so that it has the following deps:

  defp deps do
    [
      {:plug_cowboy, "~> 2.0.0"},
      {:plug, path: "../plug", override: true} # change this to your actual path
    ]
  end

Create lib/plug_example/my_app.ex with the following contents:

defmodule PlugExample.MyApp do
  use Plug.Builder

  use Plug.Debugger, otp_app: :my_app

  plug :boom

  def boom(conn, _), do: raise "oops"
end

Run it with:

mix run -e "Plug.Cowboy.http(PlugExample.MyApp, [])" --no-halt
(you won’t see any output)

Then you should be able to navigate to http://localhost:4000 and see the debugger page.

2 Likes

Thanks so much @Gazler! This will hopefully do the job! I will let you know how it goes.