defmodule Phoenix.Router do
  use GenServer.Behaviour
  alias Phoenix.Plugs
  alias Phoenix.Router.Options
  alias Phoenix.Adapters.Cowboy

  defmacro __using__(plug_adapter_options \\ []) do
    quote do
      use Phoenix.Router.Mapper
      use Phoenix.Adapters.Cowboy

      import unquote(__MODULE__)
      @before_compile unquote(__MODULE__)
      use Plug.Builder

      plug Plugs.ErrorHandler, from: __MODULE__

      @options unquote(plug_adapter_options)
    end
  end

  defmacro __before_compile__(_env) do
    quote do
      plug Plugs.CodeReloader, from: __MODULE__
      plug Plugs.Logger, from: __MODULE__
      plug :dispatch

      def dispatch(conn, []) do
        Phoenix.Router.perform_dispatch(conn, __MODULE__)
      end

      def start do
        options = Options.merge(@options, @dispatch_options, __MODULE__, Cowboy)

        IO.puts "Running #{__MODULE__} with Cowboy on port #{inspect options}"
        Plug.Adapters.Cowboy.http __MODULE__, [], options
      end
    end
  end

  def perform_dispatch(conn, router) do
    alias Phoenix.Router.Path
    conn        = Plug.Conn.fetch_params(conn)
    http_method = conn.method |> String.downcase |> binary_to_atom
    split_path  = Path.split_from_conn(conn)

    apply(router, :match, [conn, http_method, split_path])
  end
end

defmodule Phoenix.Router do
  use GenServer.Behaviour
  alias Phoenix.Plugs
  alias Phoenix.Router.Options
  alias Phoenix.Adapters.Cowboy

  defmacro __using__(plug_adapter_options \\ []) do
    quote do
      use Phoenix.Router.Mapper
      use Phoenix.Adapters.Cowboy

      import unquote(__MODULE__)
      @before_compile unquote(__MODULE__)
      use Plug.Builder

      plug Plugs.ErrorHandler, from: __MODULE__

      @options unquote(plug_adapter_options)
    end
  end

  defmacro __before_compile__(_env) do
    quote do
      plug Plugs.CodeReloader, from: __MODULE__
      plug Plugs.Logger, from: __MODULE__
      plug :dispatch

      def dispatch(conn, []) do
        Phoenix.Router.perform_dispatch(conn, __MODULE__)
      end

      def start do
        options = Options.merge(@options, @dispatch_options, __MODULE__, Cowboy)

        IO.puts "Running #{__MODULE__} with Cowboy on port #{inspect options}"
        Plug.Adapters.Cowboy.http __MODULE__, [], options
      end

      def stop do
        IO.puts "#{__MODULE__} has been stopped"
        Plug.Adapters.Cowboy.shutdown __MODULE__.HTTP
      end
    end
  end

  def perform_dispatch(conn, router) do
    alias Phoenix.Router.Path
    conn        = Plug.Conn.fetch_params(conn)
    http_method = conn.method |> String.downcase |> binary_to_atom
    split_path  = Path.split_from_conn(conn)

    apply(router, :match, [conn, http_method, split_path])
  end
end

Add stop/shutdown task to Router
Add stop/shutdown task to Router

hsavit1/phoenix,Fluxuous/phoenix,dmarkow/phoenix,ACPK/phoenix,stevedomin/phoenix,justnoxx/phoenix,sadiqmmm/phoenix,ephe-meral/phoenix,dmarkow/phoenix,mobileoverlord/phoenix,Smulligan85/phoenix,Eventacular/phoenix,kevinold/phoenix,Kosmas/phoenix,jeffkreeftmeijer/phoenix,ephe-meral/phoenix,lancehalvorsen/phoenix,michalmuskala/phoenix,jeffweiss/phoenix,jasond-s/phoenix,Rumel/phoenix,bsmr-erlang/phoenix,paulcsmith/phoenix,CD1212/phoenix,nickgartmann/phoenix,0x00evil/phoenix,Kosmas/phoenix,eksperimental/phoenix,rodrigues/phoenix,kidaa/phoenix,vic/phoenix,michalmuskala/phoenix,manukall/phoenix,seejee/phoenix,mobileoverlord/phoenix,Dahoon/phoenix,henrik/phoenix,beni55/phoenix,foxnewsnetwork/phoenix,linearregression/phoenix,doron2402/phoenix,ericmj/phoenix,Gazler/phoenix,keathley/phoenix,andrewvy/phoenix,mschae/phoenix,pap/phoenix,hotvulcan/phoenix,brucify/phoenix,cas27/phoenix,romul/phoenix,javimolla/phoenix,optikfluffel/phoenix,tony612/phoenix,Smulligan85/phoenix,evax/phoenix,rodrigues/phoenix,0x00evil/phoenix,arthurcolle/phoenix,nshafer/phoenix,yoavlt/phoenix,iStefo/phoenix,nicrioux/phoenix,Joe-noh/phoenix,Gazler/phoenix,ericmj/phoenix,phoenixframework/phoenix,FND/phoenix,nshafer/phoenix,bsmr-erlang/phoenix,GabrielNicolasAvellaneda/phoenix,omotenko/phoenix_auth,begleynk/phoenix,milafrerichs/phoenix,pap/phoenix,korobkov/phoenix,cas27/phoenix,doomspork/phoenix,phoenixframework/phoenix,yonglehou/phoenix,trarbr/phoenix,DavidAlphaFox/phoenix,0x00evil/phoenix,jamilabreu/phoenix,manukall/phoenix,bsodmike/phoenix,lono-devices/phoenix,iguberman/phoenix,mitchellhenke/phoenix,iStefo/phoenix,thegrubbsian/phoenix,robomc/phoenix,nshafer/phoenix,gjaldon/phoenix,ahmetabdi/phoenix,evax/phoenix,phoenixframework/phoenix,greyhwndz/phoenix,jamilabreu/phoenix,StevenNunez/phoenix,robhurring/phoenix,stefania11/phoenix,ugisozols/phoenix,rafbgarcia/phoenix,gjaldon/phoenix,safi/phoenix,optikfluffel/phoenix,marcioj/phoenix,optikfluffel/phoenix,bitgamma/phoenix,JHKennedy4/phoenix,wsmoak/phoenix,stevedomin/phoenix,scrogson/phoenix,rafbgarcia/phoenix,switchflip/phoenix,bdtomlin/phoenix,elliotcm/phoenix,KazuCocoa/phoenix,mvidaurre/phoenix,wicliff/phoenix,seejee/phoenix,CultivateHQ/phoenix,y-yagi/phoenix,ybur-yug/phoenix,mschae/phoenix,esbullington/phoenix-1,lono-devices/phoenix,keathley/phoenix,daytonn/phoenix,mitchellhenke/phoenix,kholbekj/phoenix,DavidAlphaFox/phoenix,trarbr/phoenix,omotenko/phoenix_auth,wsmoak/phoenix,Ben-Evolently/phoenix,korobkov/phoenix,kyledecot/phoenix,fbjork/phoenix,jwarwick/phoenix,jwarwick/phoenix,mvidaurre/phoenix,lancehalvorsen/phoenix,sdnorm/phoenix,andrewvy/phoenix,eksperimental/phoenix,vic/phoenix,rafbgarcia/phoenix,Joe-noh/phoenix,jxs/phoenix,xtity/simple_phoenix,Rumel/phoenix,VictorZeng/phoenix,ybur-yug/phoenix,CultivateHQ/phoenix,maxnordlund/phoenix,SmartCasual/phoenix