How to prevent starting another local server when having multiple apps in dev

Hi, when having multiple projects opened in terminal I wanted a way to prevent starting another server then the one I’m testing right now.

So what I do is add two lines in mix.exs, in the aliases section:

  "phx.server": "",
  "phx.MyApp": "phx.server",

In this way if I type mix phx.server nothing will happen, and if I type mix phx.MyApp in the wrong terminal also nothing will happen.

Also this is a nice way to personalize your app :slight_smile:

Do you have any thoughts on this?

Later edit:

I was wrong above, you need to create a new task for this to work, and put the default to do some dummy action:

defmodule Mix.Tasks.Startit do
  use Mix.Task

  def run([] = params) do
      Mix.Tasks.Phx.Server.run([])
  end
end

In mix.exs:

"phx.server": "help",
"phx.MyApp": "startit"

Since I’m always working in strictly isolated contexts and I also want to make it easy for new team members to pick up, I usually stick to the standard tasks and commands, whichever are idiomatic in the projects language and framework.

In the long term it’s much easier if everything is run the same way.

1 Like