|
import "phoenix_html" |
|
import {Socket} from "phoenix" |
|
import {LiveSocket} from "phoenix_live_view" |
|
|
|
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") |
|
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}) |
|
|
|
liveSocket.connect() |
|
window.liveSocket = liveSocket |
|
``` |
|
|
|
10. lib/hexalixir/application.ex: |
|
```elixir |
|
defmodule Hexalixir.Application do |
|
use Application |
|
|
|
@impl true |
|
def start(_type, _args) do |
|
children = [ |
|
HexalixirWeb.Telemetry, |
|
{Phoenix.PubSub, name: Hexalixir.PubSub}, |
|
HexalixirWeb.Endpoint, |
|
Hexalixir.Game |
|
] |
|
|
|
opts = [strategy: :one_for_one, name: Hexalixir.Supervisor] |
|
Supervisor.start_link(children, opts) |
|
end |
|
|
|
@impl true |
|
def config_change(changed, _new, removed) do |
|
HexalixirWeb.Endpoint.config_change(changed, removed) |
|
:ok |
|
end |
|
end |
|
|