-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdev.exs
113 lines (96 loc) · 2.73 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
# Development Server for Beacon LiveAdmin
#
# Usage:
#
# $ iex -S mix dev
#
# Refs:
#
# https://github.com/phoenixframework/phoenix_live_dashboard/blob/e87bbe03203f67947643f0574bb272b681951fa8/dev.exs
Logger.configure(level: :debug)
Application.put_env(:beacon_live_admin, DemoWeb.Endpoint,
adapter: Bandit.PhoenixAdapter,
url: [host: "localhost"],
secret_key_base: "TrXbWpjZWxk0GXclXOHFCoufQh1oRK0N5rev5GcpbPCsuf2C/kbYlMgeEEAXPayF",
live_view: [signing_salt: "nXvN+c8y"],
http: [port: System.get_env("PORT") || 4002],
debug_errors: true,
check_origin: false,
pubsub_server: Demo.PubSub,
watchers: [
tailwind: {Tailwind, :install_and_run, [:beacon_live_admin, ~w(--watch)]},
node: ["build.js", "--watch", cd: Path.expand("./assets", __DIR__)]
],
live_reload: [
patterns: [
~r"dist/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/static/.*(css|js)$",
~r"lib/beacon/live_admin/.*(ex)$",
~r"lib/beacon/live_admin/(components|controllers|pages)/.*(ex)$"
]
]
)
defmodule DemoWeb.CustomPage do
use Beacon.LiveAdmin.PageBuilder
@impl true
def init(opts) do
{:ok, opts}
end
@impl true
def menu_link(_prefix, _live_action), do: {:root, "Custom"}
@impl true
def mount(_params, session, socket) do
{:ok, assign(socket, :val, session.val)}
end
@impl true
def render(assigns) do
~H"""
<div>Custom</div>
<span>Val: <%= @val %></span>
"""
end
end
defmodule DemoWeb.Router do
use Phoenix.Router, helpers: false
use Beacon.LiveAdmin.Router
import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
scope "/" do
pipe_through :browser
beacon_live_admin("/admin", additional_pages: [{"/custom", DemoWeb.CustomPage, :show, %{val: 1}}])
end
end
defmodule DemoWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :beacon_live_admin
@session_options [
store: :cookie,
key: "_live_view_key",
signing_salt: "d7B1x7Tu",
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 Beacon.LiveAdmin.Plug
plug DemoWeb.Router
end
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)