Gatehouse can run a Phoenix development server behind a stable local .localhost
URL with HTTPS. This is useful when developing features that depend on secure
origins, stable callback URLs, cookies, or LiveView/WebSocket behavior.
Add Gatehouse to your Phoenix app in development:
def deps do
[
{:gatehouse, "~> 0.1", only: :dev, runtime: false}
]
endThen fetch dependencies:
mix deps.getGatehouse creates a development-only CA under ~/.gatehouse/dev_certs by
default:
mix gatehouse.trustThe task prints OS-specific trust-store commands. It intentionally does not run
sudo for you.
mix gatehouse.phxThis starts:
- a Phoenix backend on a free
127.0.0.1port exposed asPORT - a Gatehouse HTTPS proxy on
https://<app-name>.localhost:4443 - a local Gatehouse route from the
.localhosthost to the backend
Use --open to open the stable URL in your browser:
mix gatehouse.phx --openYour Phoenix endpoint must read PORT in development:
config :my_app, MyAppWeb.Endpoint,
http: [ip: {127, 0, 0, 1}, port: String.to_integer(System.get_env("PORT") || "4000")],
check_origin: ["https://my-app.localhost:4443"]Regular requests, static assets, and LiveView/WebSocket traffic are proxied through the same HTTPS origin.
Use gatehouse.run when you need a command other than mix phx.server:
mix gatehouse.run -- mix phx.server
mix gatehouse.run --open -- mix phx.server
mix gatehouse.run --host admin.localhost --proxy-port 443 -- mix phx.server
mix gatehouse.run --no-tls -- mix phx.serverOptions:
--host HOST- stable local hostname, defaults to<otp-app>.localhost--proxy-port PORT- local proxy port, defaults to4443--backend-port PORT- backend port passed to the command asPORT--cert-dir DIR- development CA/certificate directory--no-tls- expose the proxy over plain HTTP--open- open the proxy URL in your browser
Run mix gatehouse.trust and follow the printed trust-store instructions.
Update your dev endpoint to read the PORT environment variable. Gatehouse
prints the backend port it selected in the startup banner.
Stop the process using the port or choose another proxy port:
mix gatehouse.phx --proxy-port 4444