Skip to content

Commit ca0e420

Browse files
committed
Add :endpoint option, closes #18
1 parent 1ab8aa5 commit ca0e420

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

lib/phoenix_playground.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ defmodule PhoenixPlayground do
142142
host: "localhost",
143143
live_reload: true,
144144
ip: {127, 0, 0, 1},
145+
endpoint: PhoenixPlayground.Endpoint,
145146
endpoint_options: [],
146147
debug_errors: true,
147148
open_browser: true,
@@ -247,7 +248,7 @@ defmodule PhoenixPlayground do
247248
child_specs ++
248249
[
249250
{Phoenix.PubSub, name: PhoenixPlayground.PubSub},
250-
{PhoenixPlayground.Endpoint, endpoint_options}
251+
{Keyword.fetch!(options, :endpoint), endpoint_options}
251252
]
252253

253254
System.no_halt(true)

lib/phoenix_playground/router.ex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ defmodule PhoenixPlayground.Router do
1010

1111
@impl true
1212
def call(conn, []) do
13-
case PhoenixPlayground.Endpoint.config(:phoenix_playground) do
14-
[live: _live] ->
13+
endpoint = conn.private.phoenix_endpoint
14+
15+
options = endpoint.config(:phoenix_playground)
16+
17+
cond do
18+
options[:live] ->
1519
PhoenixPlayground.Router.LiveRouter.call(conn, [])
1620

17-
[controller: controller] ->
21+
controller = options[:controller] ->
1822
conn = put_in(conn.private[:phoenix_playground_controller], controller)
1923
PhoenixPlayground.Router.ControllerRouter.call(conn, [])
2024

21-
[plug: _] ->
25+
options[:plug] ->
2226
# always fetch plug from app env to allow code reloading anonymous functions
2327
plug = Application.fetch_env!(:phoenix_playground, :plug)
2428

@@ -36,8 +40,8 @@ defmodule PhoenixPlayground.Router do
3640
fun.(conn, [])
3741
end
3842

39-
other ->
40-
raise ArgumentError, "expected :live, :controller, or :plug, got: #{inspect(other)}"
43+
true ->
44+
raise ArgumentError, "expected :live, :controller, or :plug, got: #{inspect(options)}"
4145
end
4246
end
4347

lib/phoenix_playground/test.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ defmodule PhoenixPlayground.Test do
4747
@signing_salt "ll+Leuc4"
4848

4949
defmacro __using__(options) do
50-
options = Keyword.validate!(options, [:live, :controller])
50+
options =
51+
Keyword.validate!(options, [
52+
:live,
53+
:controller,
54+
endpoint: PhoenixPlayground.Endpoint
55+
])
5156

5257
imports =
5358
if options[:live] do
@@ -60,7 +65,7 @@ defmodule PhoenixPlayground.Test do
6065
import Phoenix.ConnTest
6166
unquote(imports)
6267

63-
@endpoint PhoenixPlayground.Endpoint
68+
@endpoint unquote(options[:endpoint])
6469

6570
setup do
6671
options = unquote(options)

0 commit comments

Comments
 (0)