defmodule DaProductAppWeb.Endpoint do use Phoenix.Endpoint, otp_app: :da_product_app # 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: "_da_product_app_key", signing_salt: "Ddm27qNt", same_site: "Lax" ] socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]], longpoll: [connect_info: [session: @session_options]] # 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: :da_product_app, gzip: false, only: DaProductAppWeb.static_paths() # Serve payment gateway static assets when integrated if Code.ensure_loaded?(PaymentGatewayAppWeb) do plug Plug.Static, at: "/pgpayments", from: {:payment_gateway_app, "priv/static"}, gzip: false, only: ~w(assets fonts images favicon.ico robots.txt shukria-payment-widget.js demo_checkout_page.html) end # 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 # Skip live_reload injection for payment gateway pages — it causes a # reload loop because da_product_app's esbuild --watch fires reload # signals that blink the iframe continuously. plug :maybe_live_reload plug Phoenix.CodeReloader plug Phoenix.Ecto.CheckRepoStatus, otp_app: :da_product_app 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 CORSPlug plug DaProductAppWeb.Router def init(_key, config) do {:ok, config} # Bandit will pick up the `http:` config automatically end # Skip Phoenix LiveReloader injection for payment gateway paths. # The PG iframe has its own LiveSocket; injecting the main app's # live_reload script causes a reload loop when esbuild --watch fires. defp maybe_live_reload(%Plug.Conn{request_path: "/pgpayments" <> _} = conn, _opts), do: conn defp maybe_live_reload(conn, _opts) do Phoenix.LiveReloader.call(conn, Phoenix.LiveReloader.init([])) end end