2023-03-15 01:18:15 +00:00
|
|
|
defmodule ExampleWeb.Endpoint do
|
|
|
|
|
use Phoenix.Endpoint, otp_app: :example
|
2026-03-05 22:39:36 +00:00
|
|
|
import PhoenixVite.Plug
|
2023-03-15 01:18:15 +00:00
|
|
|
|
|
|
|
|
# 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]]
|
|
|
|
|
|
2026-03-05 22:39:36 +00:00
|
|
|
plug :favicon, dev_server: {PhoenixVite.Components, :has_vite_watcher?, [__MODULE__]}
|
|
|
|
|
|
2026-02-18 19:30:17 +00:00
|
|
|
# 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
|
2026-03-06 12:02:53 +00:00
|
|
|
|
|
|
|
|
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
|
2026-02-18 19:30:17 +00:00
|
|
|
end
|
|
|
|
|
|
2023-03-15 01:18:15 +00:00
|
|
|
# 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
|
2026-02-18 19:30:17 +00:00
|
|
|
|
2026-03-06 12:02:53 +00:00
|
|
|
|
2023-03-15 01:18:15 +00:00
|
|
|
end
|