Customize Hanami / WEBrick for SSL

I am trying to setup a HTTPS environment in development.

I found that WEBrick can handle it, but I am unable to figure out where to use that in Hanami. Is there a configuration file to override default values or maybe i could provide a custom server?

Webrick https support: module WEBrick - Documentation for Ruby 2.1.0

Thank you,

Jerome

@jerome.tremblay Hi and welcome :wave:

I suggest to do this via puma.
If you add a config/puma.rb file, it will be auto-detected (Puma/Rack feature).

You should be able to achieve this via:

# config/puma.rb
# ...
# Usual Puma configuration 
# ...

localhost_key = File.join(Dir.pwd, "server.key")
localhost_crt = File.join(Dir.pwd, "server.crt")

ssl_bind "0.0.0.0", 2323, {
  key: localhost_key,
  cert: localhost_crt,
  verify_mode: 'none'
}

Then simply run bundle exec hanami server and you should be able to connect to https://0.0.0.0:2323.

2 Likes

Thank you, this is a perfect solution.

1 Like