Your Phoenix Preview Loads and Then Does Nothing
You pushed a branch, the build went green, the preview URL came back in the PR comment. You open it and the page renders — styled, correct, your markup. Then you click a button and nothing happens. No error in the browser console, no error in the logs, no failed request you can point at. The deployment is marked successful.
This is the most common way a Phoenix preview fails, and it fails quietly because the HTTP request succeeded. The socket didn't. LiveView state lives in a websocket, so a preview can serve perfect HTML and still be completely inert.
Below are the four checks that account for almost every case, ordered by how often they're the culprit. Each one is a configuration value, not a code change.
Check 1: is the release actually listening on PORT?
A Phoenix release started with bin/my_app start boots the endpoint only if server: true is set for that environment. If it isn't, the VM starts, the supervision tree comes up, and nothing binds a port. The container stays alive, so the platform has no reason to mark the deploy failed — it just serves nothing.
The reliable fix is to gate it on an environment variable in config/runtime.exs, which runs at boot rather than at compile time:
# config/runtime.exs
import Config
if config_env() == :prod do
port = String.to_integer(System.get_env("PORT") || "4000")
config :my_app, MyAppWeb.Endpoint,
server: System.get_env("PHX_SERVER") == "true",
http: [port: port]
end
Then set PHX_SERVER=true in the preview's environment variables. mix phx.gen.release generates a bin/server script that does this for you; if you're using it, confirm the script is what your start command actually invokes.
PreviewDrop sets PORT, HOST, and HOSTNAME on every preview container and routes traffic to that port. That is the complete list of injected variables — there is no PREVIEW_URL to read, so don't write code that expects one.
Check 2: is the endpoint binding to localhost?
The second half of the same config block. A http: [ip: {127, 0, 0, 1}] line is common in projects that started from a local-development template, and inside a container 127.0.0.1 is the container itself. Traffic from the router never arrives.
Leave ip unset so Phoenix binds all interfaces, or set it explicitly:
http: [ip: {0, 0, 0, 0}, port: port]
This one is worth checking even if your page loads, because it can produce partial failures — health checks that pass on an internal interface while the socket path behaves differently.
Check 3: does check_origin accept the preview hostname?
This is the check that produces the exact symptom in the title. Phoenix's socket refuses connections whose Origin header doesn't match check_origin. The production default accepts only the host from your endpoint's url config, so a preview served from a different hostname gets its socket upgrade rejected.
Preview hostnames follow prv-<id>.previews.previewdrop.dev. Allow that shape explicitly instead of disabling the check:
# config/runtime.exs
preview_host = ~r/^prv-[a-z0-9-]+\.previews\.previewdrop\.dev$/
config :my_app, MyAppWeb.Endpoint,
check_origin: [
"https://example.com",
preview_host
]
check_origin accepts a list mixing exact strings and regexes, so production stays locked to your real domain while previews pass. Do not set check_origin: false. Phoenix will refuse to boot if you also disable CSRF checks, and for good reason: an open socket origin is cross-site websocket hijacking waiting to happen. The regex costs you one line.
If you're on Phoenix 1.6.6 or later, check_origin: :conn is a reasonable alternative — it accepts any origin matching the host of the current request, which is exactly the preview case. It's less explicit than the regex, so pick one and write down why.
Check 4: does PHX_HOST match the hostname in the address bar?
Phoenix builds absolute URLs — socket paths, ~p route helpers, redirects — from url: [host: ...]. If that host is hard-coded, the socket connects to production while the page is served from the preview. The page loads from one place and talks to another.
Read the host from the environment at boot:
host = System.get_env("PHX_HOST") || raise "PHX_HOST is missing"
config :my_app, MyAppWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"]
runtime.exs is the only correct place for this. A value compiled into the release can't differ between preview and production, so a compile-time host is a preview bug by construction.
The two things that aren't configuration
Two remaining failures look like socket problems and aren't.
Unbuilt assets. Phoenix 1.7+ compiles JS and CSS through esbuild and tailwind Mix aliases. If your build command doesn't run mix assets.deploy, priv/static is empty and the page renders unstyled. It's not broken, but reviewers won't trust it, and an unstyled LiveView page often hides a real layout bug behind an obvious one. Put the asset step in the build command.
Migrations against a shared database. A preview runs your app's container; it does not come with a database attached. Point previews at a throwaway instance you control, and decide deliberately whether to run mix ecto.migrate on boot. Against a disposable database it's convenient. Against a shared development database that three other branches are using, it's how you lose an afternoon.
Getting the URL in the first place
None of the above requires a Dockerfile or a pipeline file. PreviewDrop reads mix.exs, detects Elixir, and builds the project. You can override the install, build, and start commands in Project Settings when your umbrella layout or release config needs something specific.
The loop is short: connect the repo, paste SECRET_KEY_BASE, PHX_HOST, and PHX_SERVER into the project's environment variables, then open a pull request. The first build compiles dependencies and warms the cache; later builds reuse it. When it finishes, a comment lands on the PR with the URL. Push again and the same URL updates in place. Close or merge the PR and the preview is torn down. If a build can't start the container, the deployment is marked failed with the reason shown in the dashboard rather than sitting in queued and counting against your concurrent-preview limit.
Test it with one click, not one page load
The check that matters is not "does the preview load" — it's "does an interaction round-trip." Open the preview, click something that triggers a handle_event, and watch whether the diff comes back. If it does, all four settings above are correct. If the page loads and the click does nothing, work down this list in order: PHX_SERVER, bind address, check_origin, PHX_HOST.
Start with the pull request that's been waiting longest. Read the quickstart docs for the full walkthrough, or sign up and put a live URL on your next branch. The Free plan covers two concurrent previews across three projects with a four-hour lifetime — enough to prove the loop on a real branch. Paid plans start at $19/mo for the workspace, not per seat.
Want previews on your own pull requests? Start free — 2 concurrent previews, no credit card.