Skip to content

Commit 8f96a0c

Browse files
committed
catchall route to prevent unhandled 404s, concurrency improvements
1 parent bc8b542 commit 8f96a0c

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

app/controllers/application_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ def user_not_authorized
2020
flash[:alert] = 'You are not authorized to perform this action.'
2121
redirect_to(request.referrer || root_path)
2222
end
23+
24+
def not_found
25+
render json: { error: 'Not found' }, status: 404
26+
end
2327
end

config/puma.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44
# the maximum value specified for Puma. Default is set to 5 threads for minimum
55
# and maximum; this matches the default thread size of Active Record.
66
#
7-
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8-
threads threads_count, threads_count
97

10-
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
11-
#
12-
port ENV.fetch("PORT") { 3000 }
8+
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
9+
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
10+
threads min_threads_count, max_threads_count
1311

14-
# Specifies the `environment` that Puma will run in.
15-
#
12+
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
13+
preload_app!
14+
15+
port ENV.fetch("PORT") { 3000 }
1616
environment ENV.fetch("RAILS_ENV") { "development" }
1717

18+
19+
on_worker_boot do
20+
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
21+
end
22+
23+
plugin :tmp_restart
24+
1825
# Specifies the number of `workers` to boot in clustered mode.
1926
# Workers are forked webserver processes. If using threads and workers together
2027
# the concurrency of the application would be max `threads` * `workers`.
@@ -53,4 +60,4 @@
5360
#
5461

5562
# Allow puma to be restarted by `rails restart` command.
56-
plugin :tmp_restart
63+
# plugin :tmp_restart

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@
6565
resources :cases do
6666
resources :case_comments, only: %i[new create]
6767
end
68+
69+
match '*path', to: 'application#not_found', via: :all
6870
end

0 commit comments

Comments
 (0)