Rails and WebPacker: SSL_connect error

When implementing SSO for a legacy Rails 5 application with a Puma dev environment, I encountered an issue with JavaScript content not loading on some pages. The server output the following error message:

➜ bundle exec rails s -b "ssl://localhost:3000?key=config/cert.key&cert=config/cert.crt"
=> Booting Puma
=> Rails 5.2.8.10 LTS application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Puma version: 5.6.4 (ruby 2.7.4-p191) ("Birdie's Version")
...
Started GET "/" for 127.0.0.1 at 2022-06-21 17:07:43 +1000
...
2022-06-21 17:17:21 +1000 Rack app ("GET /packs/js/form-2c133051829ab02ebb74.js" - (127.0.0.1)): #<OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: wrong version number>

The Fix

It looks like the local dev environment had previously been run under HTTP, not HTTPS. Updating the webpacker config and restarting the server resolved the issue:

➜ vim config/webpacker.yml
...
development:
  <<: *default
  compile: true
  warnings: true

  dev_server:
    host: localhost
    port: 3035
    hmr: false
    https: false # <-- set this to true
...

➜ ./bin/webpack-dev-server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s