Skip to content

Commit

Permalink
respect live_socket_path config option
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Jun 21, 2022
1 parent 7d561d7 commit b30db29
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import { Timestamp } from "./hooks/timestamp";
let csrfToken = document
.querySelector("meta[name='csrf-token']")
.getAttribute("content");
let liveSocket = new LiveSocket("/live", Socket, {
let socketPath =
document.querySelector("html").getAttribute("phx-socket") || "/live";

let liveSocket = new LiveSocket(socketPath, Socket, {
params: { _csrf_token: csrfToken },
hooks: {
Table: Table,
Expand Down
6 changes: 4 additions & 2 deletions dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule DemoWeb.Router do
scope "/", DemoWeb do
pipe_through :browser

live_exq_ui("/exq")
live_exq_ui("/exq", live_socket_path: "/exq/live")
end
end

Expand All @@ -54,7 +54,9 @@ defmodule DemoWeb.Endpoint do
signing_salt: "Y3AT90O7"
]

socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
socket "/exq/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [session: @session_options]]

socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
Expand Down
2 changes: 1 addition & 1 deletion lib/exq_ui_web/templates/layout/root.html.heex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" phx-socket={live_socket_path(@conn)}>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
Expand Down
4 changes: 4 additions & 0 deletions lib/exq_ui_web/views/layout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ defmodule ExqUIWeb.LayoutView do

def render("app.js", _), do: @app_js
def render("app.css", _), do: @app_css

def live_socket_path(conn) do
[Enum.map(conn.script_name, &["/" | &1]) | conn.private.live_socket_path]
end
end
2 changes: 1 addition & 1 deletion priv/static/js/app.js

Large diffs are not rendered by default.

0 comments on commit b30db29

Please sign in to comment.