Original source here.
https://github.com/FiloSottile/mkcert
So the first thing you will need to do is to create a certificate for your service you want to add the HTTPS connection. Let's use mkcert to generate it, i'm going to localhost, but you can use whatever name you want
➜ ~ mkcert localhost
For Mac users open the Keychain Access and drag the certificate to the Keychain. For the localhost.pem file you could see some error, but it will end up adding it.
Double-click the cert you just added, click the -> Trust
And at the When using this certificate: select the Always Trust option.
Add the following snippet to config/puma.rb
:
if ENV['RACK_ENV'] == 'development'
localhost_key = "#{File.join('config', 'local-certs', 'localhost-key.pem')}"
localhost_crt = "#{File.join('config', 'local-certs', 'localhost.pem')}"
# To be able to use rake etc
ssl_bind '0.0.0.0', 3000, {
key: localhost_key,
cert: localhost_crt,
verify_mode: 'none'
}
end
In .env
file, set RAILS_HOST=localhost:3001
Now, when you run puma with rails s
, you should see how it listening for ssl requests:
=> Booting Puma
=> Rails 6.1.3.1 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.2.2 (ruby 3.0.0-p0) ("Fettisdagsbulle")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 1443
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
* Listening on ssl://0.0.0.0:3001?cert=/Users/borjagvo/Work/templarbit/app-v2/localhost.pem&key=/Users/borjagvo/Work/templarbit/app-v2/localhost-key.pem&verify_mode=none
Use Ctrl-C to stop