-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathlive_debugger.ex
More file actions
90 lines (74 loc) · 2.66 KB
/
live_debugger.ex
File metadata and controls
90 lines (74 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
defmodule LiveDebugger do
@moduledoc """
Debugger for LiveView applications.
"""
use Application
@app_name :live_debugger
@default_ip {127, 0, 0, 1}
@default_port 4007
@default_secret_key_base "DEFAULT_SECRET_KEY_BASE_1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcd"
@default_signing_salt "live_debugger_signing_salt"
@assets_path "assets/live_debugger/client.js"
def start(_type, _args) do
config = Application.get_all_env(@app_name)
put_endpoint_config(config)
put_live_debugger_tags(config)
children = [
{Phoenix.PubSub, name: LiveDebugger.PubSub},
{LiveDebugger.Endpoint,
[
check_origin: false,
pubsub_server: LiveDebugger.PubSub
]}
]
children =
if LiveDebugger.Env.unit_test?() do
children
else
children ++
[
{LiveDebugger.GenServers.CallbackTracingServer, []}
]
end
Supervisor.start_link(children, strategy: :one_for_one, name: LiveDebugger.Supervisor)
end
defp default_adapter() do
case Code.ensure_loaded(Bandit.PhoenixAdapter) do
{:module, _} -> Bandit.PhoenixAdapter
{:error, _} -> Phoenix.Endpoint.Cowboy2Adapter
end
end
defp put_endpoint_config(config) do
endpoint_config =
[
http: [
ip: Keyword.get(config, :ip, @default_ip),
port: Keyword.get(config, :port, @default_port)
],
secret_key_base: Keyword.get(config, :secret_key_base, @default_secret_key_base),
live_view: [signing_salt: Keyword.get(config, :signing_salt, @default_signing_salt)],
adapter: Keyword.get(config, :adapter, default_adapter()),
live_reload: Keyword.get(config, :live_reload, []),
server: true
]
Application.put_env(@app_name, LiveDebugger.Endpoint, endpoint_config)
end
defp put_live_debugger_tags(config) do
ip_string = config |> Keyword.get(:ip, @default_ip) |> :inet.ntoa() |> List.to_string()
port = Keyword.get(config, :port, @default_port)
browser_features? = Keyword.get(config, :browser_features?, true)
debug_button? = Keyword.get(config, :debug_button?, true)
highlighting? = Keyword.get(config, :highlighting?, true)
live_debugger_url = "http://#{ip_string}:#{port}"
live_debugger_assets_url = "http://#{ip_string}:#{port}/#{@assets_path}"
assigns = %{
url: live_debugger_url,
assets_url: live_debugger_assets_url,
browser_features?: browser_features?,
debug_button?: debug_button?,
highlighting?: highlighting?
}
tags = LiveDebugger.Components.Config.live_debugger_tags(assigns)
Application.put_env(@app_name, :live_debugger_tags, tags)
end
end