From b5052d4beeb7fd0bc14db21336588bb0483f7d09 Mon Sep 17 00:00:00 2001 From: hellekin Date: Tue, 6 Oct 2020 19:27:52 +0200 Subject: Facilitate development with puma in the browser A single worker in development enables in-context debug in the error console in the browser. --- config/puma.rb | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'config') diff --git a/config/puma.rb b/config/puma.rb index 2d0dae8..98bdd50 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -14,46 +14,42 @@ threads min_threads_count, max_threads_count app_dir = File.expand_path('../..', __FILE__) shared_dir = "#{app_dir}/tmp" +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -if Rails.env.development? - port ENV.fetch("PORT") { 3000 } -else +if Rails.env.production? + # Bind to a (faster) socket bind "unix://#{shared_dir}/sockets/puma.sock"; + # Log production errors + stdout_redirect "#{app_dir}/log/puma.stdout.log", "#{app_dir}/log/puma.stderr.log", true + # Specifies the number of `workers` to boot in clustered mode. + # Workers are forked web server processes. If using threads and workers together + # the concurrency of the application would be max `threads` * `workers`. + # Workers do not work on JRuby or Windows (both of which do not support + # processes). + # + workers ENV.fetch("WEB_CONCURRENCY") { 2 } + # Use the `preload_app!` method when specifying a `workers` number. + # This directive tells Puma to first boot the application and load code + # before forking the application. This takes advantage of Copy On Write + # process behavior so workers use less memory. + # + preload_app! +else + port ENV.fetch("PORT") { 3000 } + # Do not redirect STDOUT so we can use byebug! + stdout_redirect nil, "#{app_dir}/log/puma.stderr.log", true + workers 1 # Enable web console debug during development end -# Specifies the `environment` that Puma will run in. -# -environment ENV.fetch("RAILS_ENV") { "development" } - # Specifies the `pidfile` that Puma will use. pidfile ENV.fetch("PIDFILE") { "#{shared_dir}/pids/server.pid" } # Keep puma state state_path "#{shared_dir}/pids/puma.state" -# Logging -if Rails.env.development? - # Do not redirect STDOUT so we can use byebug! - stdout_redirect nil, "#{app_dir}/log/puma.stderr.log", true -else - stdout_redirect "#{app_dir}/log/puma.stdout.log", "#{app_dir}/log/puma.stderr.log", true -end - -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked web server processes. If using threads and workers together -# the concurrency of the application would be max `threads` * `workers`. -# Workers do not work on JRuby or Windows (both of which do not support -# processes). -# -workers ENV.fetch("WEB_CONCURRENCY") { 2 } - -# Use the `preload_app!` method when specifying a `workers` number. -# This directive tells Puma to first boot the application and load code -# before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. -# -preload_app! - # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart # Better integration with systemd -- cgit v1.2.3