File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424
2525 config . active_storage . variant_processor = :mini_magick
2626
27- config . force_ssl = true
27+ # Disable force_ssl for health checks - Railway handles SSL termination
28+ config . force_ssl = false
2829
2930 config . log_level = :info
3031
3132 config . log_tags = [ :request_id ]
3233
33- config . cache_store = :redis_cache_store , { url : ENV [ 'REDIS_URL' ] }
34+ # Use Redis for caching if available, otherwise fall back to memory store
35+ config . cache_store = if ENV [ 'REDIS_URL' ] . present?
36+ :redis_cache_store , {
37+ url : ENV [ 'REDIS_URL' ] ,
38+ reconnect_attempts : 3 ,
39+ error_handler : -> ( method :, returning :, exception :) {
40+ Rails . logger . warn "Rails cache Redis error: #{ exception . message } "
41+ }
42+ }
43+ else
44+ :memory_store
45+ end
3446
3547 config . active_job . queue_adapter = :sidekiq
3648
Original file line number Diff line number Diff line change @@ -5,12 +5,21 @@ class Attack
55 # Enable caching for Rack::Attack
66 # Development: MemoryStore (simples e rápido)
77 # Production: Redis DB 0 (persistente, compartilhado entre replicas)
8- Rack ::Attack . cache . store = if Rails . env . production?
9- ActiveSupport ::Cache ::RedisCacheStore . new (
10- url : ENV . fetch ( 'REDIS_URL' , 'redis://localhost:6379/0' ) ,
11- reconnect_attempts : 3 ,
12- namespace : 'rack_attack'
13- )
8+ # Falls back to MemoryStore if Redis is unavailable
9+ Rack ::Attack . cache . store = if Rails . env . production? && ENV [ 'REDIS_URL' ] . present?
10+ begin
11+ ActiveSupport ::Cache ::RedisCacheStore . new (
12+ url : ENV [ 'REDIS_URL' ] ,
13+ reconnect_attempts : 3 ,
14+ error_handler : -> ( method :, returning :, exception :) {
15+ Rails . logger . warn "Rack::Attack Redis error: #{ exception . message } "
16+ } ,
17+ namespace : 'rack_attack'
18+ )
19+ rescue => e
20+ Rails . logger . warn "Failed to connect to Redis for Rack::Attack, falling back to MemoryStore: #{ e . message } "
21+ ActiveSupport ::Cache ::MemoryStore . new
22+ end
1423 else
1524 ActiveSupport ::Cache ::MemoryStore . new
1625 end
You can’t perform that action at this time.
0 commit comments