Class: Ruact::Railtie
- Inherits:
-
Rails::Railtie
- Object
- Rails::Railtie
- Ruact::Railtie
- Defined in:
- lib/ruact/railtie.rb
Class Method Summary collapse
-
.check_manifest!(manifest_path) ⇒ Object
Checks whether the manifest exists and either warns (dev) or raises (prod).
-
.check_vite! ⇒ Object
Checks whether the Vite dev server is accessible and warns if not (AC#4).
-
.detect_streaming_mode! ⇒ Object
Detects the web server at boot, stores the streaming mode, and logs the result (AC#1–3).
Class Method Details
.check_manifest!(manifest_path) ⇒ Object
Checks whether the manifest exists and either warns (dev) or raises (prod). Extracted as a class method for direct testability without a full Rails app.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ruact/railtie.rb', line 88 def self.check_manifest!(manifest_path) if Rails.env.production? raise ManifestError, "react-client-manifest.json not found — run vite build before deploying" else Rails.logger.warn "[ruact] react-client-manifest.json not found at " \ "#{manifest_path} — RSC rendering will be unavailable. " \ "Run 'npm run build' or start the Vite dev server." end end |
.check_vite! ⇒ Object
Checks whether the Vite dev server is accessible and warns if not (AC#4). Extracted as a class method for direct testability without a full Rails app.
78 79 80 81 82 83 84 |
# File 'lib/ruact/railtie.rb', line 78 def self.check_vite! require "socket" TCPSocket.new("localhost", 5173).close rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH Rails.logger.warn "[ruact] Vite dev server not detected at localhost:5173 " \ "— run npm run dev for HMR" end |
.detect_streaming_mode! ⇒ Object
Detects the web server at boot, stores the streaming mode, and logs the result (AC#1–3). Detection is constant-based (zero I/O): Puma → enabled, Unicorn/Passenger → buffered, unknown → buffered (safe mode).
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ruact/railtie.rb', line 57 def self.detect_streaming_mode! mode, label = if defined?(::Puma::Server) [:enabled, "Puma detected"] elsif defined?(::Falcon::Server) [:enabled, "Falcon detected"] elsif defined?(::Unicorn) [:buffered, "Unicorn detected"] elsif defined?(::PhusionPassenger) [:buffered, "Passenger detected"] else [:buffered, "server unknown — defaulting to safe mode"] end Ruact.streaming_mode = mode verb = mode == :enabled ? "enabled" : "buffered" Rails.logger.info "[ruact] streaming: #{verb} (#{label})" mode end |