Skip to content

Bind the generated dev server to localhost - #479

Open
parndt wants to merge 1 commit into
mainfrom
bind-dev-server-to-localhost
Open

parndt wants to merge 1 commit into
mainfrom
bind-dev-server-to-localhost

Conversation

@parndt

@parndt parndt commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The config/puma.rb generated by hanami new calls port without a host, so Puma listens on every interface. In development this makes the app, along with anything mounted for local use only, reachable from every other machine on the same network, such as office, café, or conference Wi-Fi.

This binds to localhost in development, which Puma resolves to both 127.0.0.1 and ::1. Other environments keep binding all interfaces as before. Setting HANAMI_HOST widens the bind for setups that need it, like running the dev server inside a container, and hanami server --host still takes precedence over the config file.

@parndt
parndt force-pushed the bind-dev-server-to-localhost branch from ed02e8f to c9f9d34 Compare November 24, 2026 03:45
@parndt
parndt requested a review from timriley November 24, 2026 03:46
@parndt
parndt force-pushed the bind-dev-server-to-localhost branch 3 times, most recently from 82195b5 to 2638d12 Compare November 24, 2026 04:00
The generated config/puma.rb calls `port` without a host, so Puma
listens on every interface. In development that exposes the app, and
anything mounted for local use only, to every other machine on the same
network, such as office, café, or conference Wi-Fi.

Bind to localhost in development instead, which Puma resolves to every
loopback address (127.0.0.1 and ::1), and leave other environments
binding all interfaces as before. HANAMI_HOST overrides the host for
cases that need a wider bind, like a dev server inside a container.
`hanami server --host` still takes precedence over the config file.

The environment is read the same way Hanami reads it, from HANAMI_ENV,
then APP_ENV, and then RACK_ENV, so an app deployed with only RACK_ENV
set to production keeps listening on all interfaces rather than
becoming unreachable. An empty HANAMI_HOST is treated as unset, since
Puma reads an empty host as 0.0.0.0, which would quietly undo the
localhost bind when a variable is passed through without a value.
@parndt
parndt force-pushed the bind-dev-server-to-localhost branch from 2638d12 to 77d190c Compare November 24, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant