2021-09-24 puma x localhost を使ってみる
puma で localhost gem がサポートされた
puma 5.5.0 で socketry/localhost gem とのインテグレーションがサポートされた。
The headline feature of this release is a new integration with the localhost gem. Localhost takes care of creating a self-signed SSL certificate for you in development. Require it in your config.ru:
# Sinatra
require './app'
require 'localhost/authority'
run Sinatra::Application
# Rails
require 'localhost/authority' if Rails.env.development?
run MyRailsApp::Application
使ってみた
Gemfile
:
group :development do
...
gem 'localhost', require: 'localhost/authority'
...
end
config.ru
:
...
require 'localhost/authority' if Rails.env.development?
起動する。(このへんはREADMEを参考 )
$ bundle exec puma -b 'ssl://localhost:9292' config.ru
Puma starting in single mode...
* Puma version: 5.5.0 (ruby 3.0.2-p107) ("Zawgyi")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 40978
* Listening on ssl://127.0.0.1:9292?
* Listening on ssl://[::1]:9292?
Use Ctrl-C to stop
ブラウザによってはオレオレ証明でアクセスできない場合があるので注意。
下記の対応とかで解決できそう。