Skip to content

Instantly share code, notes, and snippets.

@kseki
Last active December 31, 2021 11:01
Show Gist options
  • Save kseki/bdd31b60f3ce1efff7846849687b26ea to your computer and use it in GitHub Desktop.
Save kseki/bdd31b60f3ce1efff7846849687b26ea to your computer and use it in GitHub Desktop.
Localhost gem for SSL(https) connection in the Rails development environment.
gem 'rails'
gem 'puma'
# 1. Add localhost gem.
group(:development) do
gem 'localhost'
end
# config/puma.rb
# 2. Add SSL bind setting
require 'localhost/authority'
authority = Localhost::Authority.fetch
ssl_bind '127.0.0.1', '3001', {
key: authority.key_path,
cert: authority.certificate_path
}
# 3. Comment out this line
# port ENV.fetch("PORT") { 3000 }
$ rails server
=> Booting Puma
=> Rails 7.0.0 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.5.2 (ruby 3.0.2-p107) ("Zawgyi")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 79764
* Listening on ssl://127.0.0.1:3000?cert=/Users/kseki/.localhost/localhost.crt&key=/Users/kseki/.localhost/localhost.key&verify_mode=none
Use Ctrl-C to stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment