diff --git a/CHANGELOG.md b/CHANGELOG.md index 27d4fa76..8f5b753e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Break Versioning](https://www.taoensso.com/break-ve - Print clearer errors when Postgres CLI commands fail. (@mddelk in #437) - Print clear errors from `hanami db` commands for unsupported database URL schemes and for database URLs that cannot be parsed, rather than raising a `RuntimeError` or `URI::InvalidURIError`. Neither error includes the URL, since it may contain credentials. (@parndt in #463) +- In the `config/puma.rb`, generated by `hanami new`, listen on localhost only in development, so the dev server isn't reachable from other machines on your network. Set `HANAMI_HOST` to listen on another address, such as `0.0.0.0` inside a container. Existing apps can copy the change into their own `config/puma.rb`. (@parndt in #479) - Ignore SQLite's `-wal`, `-shm` and `-journal` files in the `.gitignore` generated by `hanami new`, by widening `db/*.sqlite` to `db/*.sqlite*`. (@cllns in #451) - When the app's `config.code_reloading` is enabled, `reload` in `hanami console` will reload the app in place, preserving your local session. Otherwise, the console restarts as before. (@afomera and @timriley in #444) - Use Dry CLI 2.0 (@timriley) diff --git a/lib/hanami/cli/generators/gem/app/puma.erb b/lib/hanami/cli/generators/gem/app/puma.erb index f45cc201..98f69b30 100644 --- a/lib/hanami/cli/generators/gem/app/puma.erb +++ b/lib/hanami/cli/generators/gem/app/puma.erb @@ -1,10 +1,16 @@ # frozen_string_literal: true # -# Environment and port +# Environment, host, and port # -port ENV.fetch("<%= Hanami::Port::ENV_VAR %>", <%= Hanami::Port::DEFAULT %>) -environment ENV.fetch("HANAMI_ENV", "development") +hanami_env = ENV["HANAMI_ENV"] || ENV["APP_ENV"] || ENV["RACK_ENV"] || "development" +environment hanami_env + +# In development, listen on localhost only, so the server isn't reachable from other machines on +# your network. Set HANAMI_HOST to listen on another address, such as 0.0.0.0 inside a container. +host = ENV["HANAMI_HOST"] unless ENV["HANAMI_HOST"].to_s.empty? +host ||= "localhost" if hanami_env == "development" +port ENV.fetch("<%= Hanami::Port::ENV_VAR %>", <%= Hanami::Port::DEFAULT %>), host # # Threads within each Puma/Ruby process (aka worker) diff --git a/spec/unit/hanami/cli/commands/gem/new_spec.rb b/spec/unit/hanami/cli/commands/gem/new_spec.rb index 40fad180..554395ae 100644 --- a/spec/unit/hanami/cli/commands/gem/new_spec.rb +++ b/spec/unit/hanami/cli/commands/gem/new_spec.rb @@ -380,10 +380,16 @@ class Routes < Hanami::Routes # frozen_string_literal: true # - # Environment and port + # Environment, host, and port # - port ENV.fetch("HANAMI_PORT", 2300) - environment ENV.fetch("HANAMI_ENV", "development") + hanami_env = ENV["HANAMI_ENV"] || ENV["APP_ENV"] || ENV["RACK_ENV"] || "development" + environment hanami_env + + # In development, listen on localhost only, so the server isn't reachable from other machines on + # your network. Set HANAMI_HOST to listen on another address, such as 0.0.0.0 inside a container. + host = ENV["HANAMI_HOST"] unless ENV["HANAMI_HOST"].to_s.empty? + host ||= "localhost" if hanami_env == "development" + port ENV.fetch("HANAMI_PORT", 2300), host # # Threads within each Puma/Ruby process (aka worker) @@ -1070,10 +1076,16 @@ class Routes < Hanami::Routes # frozen_string_literal: true # - # Environment and port + # Environment, host, and port # - port ENV.fetch("HANAMI_PORT", 2300) - environment ENV.fetch("HANAMI_ENV", "development") + hanami_env = ENV["HANAMI_ENV"] || ENV["APP_ENV"] || ENV["RACK_ENV"] || "development" + environment hanami_env + + # In development, listen on localhost only, so the server isn't reachable from other machines on + # your network. Set HANAMI_HOST to listen on another address, such as 0.0.0.0 inside a container. + host = ENV["HANAMI_HOST"] unless ENV["HANAMI_HOST"].to_s.empty? + host ||= "localhost" if hanami_env == "development" + port ENV.fetch("HANAMI_PORT", 2300), host # # Threads within each Puma/Ruby process (aka worker)