-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdev.exs
103 lines (85 loc) · 2.38 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
# iex -S mix run dev.exs
Logger.configure(level: :debug)
# Configures the endpoint
Application.put_env(:backdoor, DemoWeb.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: Demo.PubSub,
watchers: [
node: [
"node_modules/webpack/bin/webpack.js",
"--mode",
"production",
"--watch",
cd: "assets"
]
],
live_reload: [
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"lib/backdoor/(live|views)/.*(ex)$",
~r"lib/backdoor/templates/.*(ex)$"
]
]
)
defmodule DemoWeb.PageController do
import Plug.Conn
def init(opts), do: opts
def call(conn, :index) do
content(conn, """
<h2>Backdoor Dev</h2>
<a href="/backdoor" target="_blank">Open Backdoor</a>
""")
end
def call(conn, :hello) do
name = Map.get(conn.params, "name", "friend")
content(conn, "<p>Hello, #{name}!</p>")
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 DemoWeb.Router do
use Phoenix.Router
import Backdoor.Router
pipeline :browser do
plug :fetch_session
end
scope "/" do
pipe_through :browser
get "/", DemoWeb.PageController, :index
get "/hello", DemoWeb.PageController, :hello
get "/hello/:name", DemoWeb.PageController, :hello
backdoor("/backdoor")
end
end
defmodule DemoWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :backdoor
socket "/live", Phoenix.LiveView.Socket
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
plug Plug.Session,
store: :cookie,
key: "_live_view_key",
signing_salt: "/VEDsdfsffMnp5"
plug Plug.RequestId
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
plug DemoWeb.Router
end
Application.ensure_all_started(:os_mon)
Application.put_env(:phoenix, :serve_endpoints, true)
Task.start(fn ->
children = [
{Phoenix.PubSub, [name: Demo.PubSub, adapter: Phoenix.PubSub.PG2]},
DemoWeb.Endpoint
]
{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)
Process.sleep(:infinity)
end)