forked from elixir-error-tracker/error-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.exs
170 lines (138 loc) · 4.5 KB
/
dev.exs
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#######################################
# Development Server for ErrorTracker.
#
# Based on PhoenixLiveDashboard code.
#
# Usage:
#
# $ iex -S mix dev
#######################################
Logger.configure(level: :debug)
# Get local configuration
Code.require_file("dev.local.exs")
# Prepare the repo
defmodule ErrorTrackerDev.Repo do
use Ecto.Repo, otp_app: :error_tracker, adapter: Ecto.Adapters.Postgres
end
_ = Ecto.Adapters.Postgres.storage_up(ErrorTrackerDev.Repo.config())
# Configures the endpoint
Application.put_env(:error_tracker, ErrorTrackerDevWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "Hu4qQN3iKzTV4fJxhorPQlA/osH9fAMtbtjVS58PFgfw3ja5Z18Q/WSNR9wP4OfW",
live_view: [signing_salt: "hMegieSe"],
http: [port: System.get_env("PORT") || 4000],
debug_errors: true,
check_origin: false,
pubsub_server: ErrorTrackerDev.PubSub,
watchers: [
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
],
live_reload: [
patterns: [
~r"dev.exs$",
~r"dist/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"lib/error_tracker/web/(live|views)/.*(ex)$",
~r"lib/error_tracker/web/templates/.*(ex)$"
]
]
)
# Setup up the ErrorTracker configuration
Application.put_env(:error_tracker, :repo, ErrorTrackerDev.Repo)
Application.put_env(:error_tracker, :otp_app, :error_tracker_dev)
Application.put_env(:error_tracker, :prefix, "private")
defmodule ErrorTrackerDevWeb.PageController do
import Plug.Conn
def init(opts), do: opts
def call(conn, :index) do
content(conn, """
<h2>ErrorTracker Dev Server</h2>
<div><a href="/dev/errors">Open ErrorTracker</a></div>
<div><a href="/plug-exception">Generate Plug exception</a></div>
<div><a href="/404">Generate Router 404</a></div>
<div><a href="/noroute">Raise NoRouteError from a controller</a></div>
<div><a href="/exception">Generate Exception</a></div>
<div><a href="/exit">Generate Exit</a></div>
""")
end
def call(conn, :noroute) do
raise Phoenix.Router.NoRouteError, conn: conn, router: ErrorTrackerDevWeb.Router
end
def call(_conn, :exception) do
raise "This is a controller exception"
end
def call(_conn, :exit) do
exit(:timeout)
end
defp content(conn, content) do
conn
|> put_resp_header("content-type", "text/html")
|> send_resp(200, "<!doctype html><html><body>#{content}</body></html>")
end
end
defmodule ErrorTrackerDevWeb.ErrorView do
def render("404.html", _assigns) do
"This is a 404"
end
def render("500.html", _assigns) do
"This is a 500"
end
end
defmodule ErrorTrackerDevWeb.Router do
use Phoenix.Router
use ErrorTracker.Web, :router
pipeline :browser do
plug :fetch_session
plug :protect_from_forgery
end
scope "/" do
pipe_through :browser
get "/", ErrorTrackerDevWeb.PageController, :index
get "/noroute", ErrorTrackerDevWeb.PageController, :noroute
get "/exception", ErrorTrackerDevWeb.PageController, :exception
get "/exit", ErrorTrackerDevWeb.PageController, :exit
scope "/dev" do
error_tracker_dashboard("/errors")
end
end
end
defmodule ErrorTrackerDevWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :error_tracker
use ErrorTracker.Integrations.Plug
@session_options [
store: :cookie,
key: "_error_tracker_dev",
signing_salt: "/VEDsdfsffMnp5",
same_site: "Lax"
]
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
plug Plug.Session, @session_options
plug Plug.RequestId
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
plug :maybe_exception
plug ErrorTrackerDevWeb.Router
def maybe_exception(%Plug.Conn{path_info: ["plug-exception"]}, _), do: raise("Plug exception")
def maybe_exception(conn, _), do: conn
end
defmodule Migration0 do
use Ecto.Migration
def up, do: ErrorTracker.Migration.up(prefix: "private")
def down, do: ErrorTracker.Migration.down(prefix: "private")
end
Application.put_env(:phoenix, :serve_endpoints, true)
Task.async(fn ->
children = [
{Phoenix.PubSub, [name: ErrorTrackerDev.PubSub, adapter: Phoenix.PubSub.PG2]},
ErrorTrackerDev.Repo,
ErrorTrackerDevWeb.Endpoint
]
{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)
# Automatically run the migrations on boot
Ecto.Migrator.run(ErrorTrackerDev.Repo, [{0, Migration0}], :up,
all: true,
log_migrations_sql: :debug
)
Process.sleep(:infinity)
end)