-
Notifications
You must be signed in to change notification settings - Fork 329
Add Phoenix LiveDashboard on a separate port #4119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
baaf5cc
Add Phoenix LiveDashboard on a separate port
alco 05d1eba
Upgrade Bandit
alco 673bd84
Remove LiveDashboardMetrics
alco e019c0e
Configure a real secret key base for live dashboard
alco 5a378dc
Include formatting rules from phoenix
alco 83bd636
Randomize lv salts
alco 334d984
Fix review feedback about naming consistency
alco ab11ebe
Turn favicon controller into a Phoenix controller
alco 623142b
Document unauthenticated setup of live dashboard
alco 9bac2eb
Add changeset
alco dfc78e8
Document Phoenix LiveDashboard in repo README
alco 46eead6
Address review feedback on LiveDashboard PR
alco de512b2
Move LiveDashboard modules under Electric.LiveDashboard namespace
alco 770e8a5
fixup! Move LiveDashboard modules under Electric.LiveDashboard namespace
alco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@core/sync-service': patch | ||
| --- | ||
|
|
||
| Add optional PhoenixLiveDashboard with configurable port to listen on. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # Used by "mix format" | ||
| [ | ||
| inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
| import_deps: [:plug, :stream_data] | ||
| import_deps: [:plug, :stream_data, :phoenix] | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| defmodule Electric.ErrorView do | ||
|
alco marked this conversation as resolved.
Outdated
|
||
| @moduledoc """ | ||
| Error view for the LiveDashboard endpoint. | ||
| Handles rendering of HTTP errors. | ||
| """ | ||
|
|
||
| def render(template, _assigns) do | ||
| Phoenix.Controller.status_message_from_template(template) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| defmodule Electric.FaviconController do | ||
|
alco marked this conversation as resolved.
Outdated
|
||
| @moduledoc """ | ||
| Simple controller to handle favicon requests. | ||
| Returns a 204 No Content response to avoid 500 errors. | ||
| """ | ||
|
|
||
| use Phoenix.Controller, formats: [:html] | ||
|
|
||
| def show(conn, _params) do | ||
| send_resp(conn, 204, "") | ||
| end | ||
| end | ||
44 changes: 44 additions & 0 deletions
44
packages/sync-service/lib/electric/live_dashboard_endpoint.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| defmodule Electric.LiveDashboardEndpoint do | ||
|
alco marked this conversation as resolved.
Outdated
|
||
| @moduledoc """ | ||
| Phoenix Endpoint for serving LiveDashboard on a separate port. | ||
| This runs independently from the main Plug-based HTTP server. | ||
|
|
||
| **WARNING: This endpoint is completely unauthenticated.** It exposes internal | ||
| system state (VM metrics, process info, etc.). In production, ensure the | ||
| dashboard port is not publicly accessible — use firewall rules or network | ||
| policies to restrict access. | ||
| """ | ||
|
|
||
| use Phoenix.Endpoint, otp_app: :electric | ||
|
|
||
| # LiveView socket for dashboard interactions | ||
| socket "/live", Phoenix.LiveView.Socket, | ||
| websocket: true, | ||
| longpoll: true | ||
|
|
||
| # Serve static assets for LiveDashboard | ||
| plug Plug.Static, | ||
| at: "/", | ||
| from: :phoenix_live_dashboard, | ||
| gzip: false, | ||
| only: ~w(assets fonts images priv) | ||
|
|
||
| # Session configuration for LiveView | ||
| plug Plug.Session, | ||
| store: :cookie, | ||
| key: "_live_dashboard_key", | ||
| signing_salt: "abc43s8Z", | ||
| same_site: "Lax" | ||
|
|
||
| # Parse request body for LiveView | ||
| plug Plug.Parsers, | ||
| parsers: [:urlencoded, :multipart, :json], | ||
| pass: ["*/*"], | ||
| json_decoder: Jason | ||
|
|
||
| plug Plug.MethodOverride | ||
| plug Plug.Head | ||
|
|
||
| # Route all requests to the LiveDashboard router | ||
| plug Electric.LiveDashboardRouter | ||
| end | ||
26 changes: 26 additions & 0 deletions
26
packages/sync-service/lib/electric/live_dashboard_router.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| defmodule Electric.LiveDashboardRouter do | ||
|
alco marked this conversation as resolved.
Outdated
|
||
| @moduledoc """ | ||
| Phoenix Router for LiveDashboard. | ||
| Mounts the dashboard at the root path. | ||
| """ | ||
|
|
||
| use Phoenix.Router | ||
| import Phoenix.LiveDashboard.Router | ||
|
|
||
| pipeline :browser do | ||
| plug :accepts, ["html", "json"] | ||
| plug :fetch_session | ||
| plug :put_root_layout, html: {Phoenix.LiveDashboard.LayoutView, :root} | ||
| plug :protect_from_forgery | ||
| plug :put_secure_browser_headers | ||
| end | ||
|
|
||
| scope "/" do | ||
| pipe_through :browser | ||
|
|
||
| # Handle favicon requests gracefully | ||
| get "/favicon.ico", Electric.FaviconController, :show | ||
|
|
||
| live_dashboard "/", ecto_repos: [] | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.