live_svelte/example_project/lib/example_web/endpoint.ex

71 lines
2.1 KiB
Elixir

defmodule ExampleWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :example
import PhoenixVite.Plug
# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it.
@session_options [
store: :cookie,
key: "_example_key",
signing_salt: "co1uLGVh",
same_site: "Lax"
]
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
plug :favicon, dev_server: {PhoenixVite.Components, :has_vite_watcher?, [__MODULE__]}
# In test, prevent caching of assets so E2E always loads the latest app.js after mix assets.js
if Mix.env() == :test do
plug :no_cache_assets
defp no_cache_assets(conn, _opts) do
Plug.Conn.register_before_send(conn, fn c ->
if String.starts_with?(c.request_path, "/assets/") do
Plug.Conn.put_resp_header(c, "cache-control", "no-store, no-cache, must-revalidate")
else
c
end
end)
end
end
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phx.digest
# when deploying your static files in production.
plug Plug.Static,
at: "/",
from: :example,
gzip: false,
only: ExampleWeb.static_paths()
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :example
end
plug Phoenix.LiveDashboard.RequestLogger,
param_key: "request_logger",
cookie_key: "request_logger"
plug Plug.RequestId
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Phoenix.json_library()
plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session, @session_options
plug ExampleWeb.Router
end