This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add local dev server mix task for developing against heimdall (#10)
- Loading branch information
1 parent
f409626
commit 29997ea
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
defmodule Mix.Tasks.DevServer do | ||
@moduledoc false | ||
use Mix.Task | ||
|
||
def filters(plugs) do | ||
plugs | ||
|> String.split(",") | ||
|> Poison.encode! | ||
end | ||
|
||
def options(opts) do | ||
opts | ||
|> String.split(",") | ||
|> Enum.map(&String.split(&1, "=")) | ||
|> Enum.map(fn [k, v | _] -> {k, v} end) | ||
|> Enum.into(%{}) | ||
|> Poison.encode!() | ||
end | ||
|
||
def routes_from_args(args) do | ||
cond do | ||
length(args) == 0 -> [] | ||
length(args) < 4 -> | ||
IO.puts "Not enough parameters for args:" | ||
IO.inspect args | ||
[] | ||
true -> | ||
[host, path, plugs, opts | tail] = args | ||
app = %{ | ||
"labels" => %{ | ||
"heimdall.host" => host, | ||
"heimdall.path" => path, | ||
"heimdall.filters" => filters(plugs), | ||
"heimdall.options" => options(opts) | ||
} | ||
} | ||
[app] ++ routes_from_args(tail) | ||
end | ||
end | ||
|
||
def run(args) do | ||
Mix.Config.persist(heimdall: [register_marathon: false]) | ||
Mix.Task.run "app.start", [] | ||
routes = | ||
args | ||
|> routes_from_args | ||
|> Heimdall.Marathon.BingeWatch.build_routes | ||
|> Heimdall.Marathon.BingeWatch.register_routes | ||
IO.puts "Registered routes:" | ||
IO.inspect routes | ||
:timer.sleep(:infinity) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule Heimdall.Plug.NoOp do | ||
@moduledoc """ | ||
A plug that does nothing. | ||
""" | ||
|
||
def init(opts), do: opts | ||
def call(conn, _opts), do: conn | ||
end |