Class: Ruflet::Rails::Protocol::WebAppEndpoint
- Inherits:
-
Object
- Object
- Ruflet::Rails::Protocol::WebAppEndpoint
- Defined in:
- lib/ruflet/rails/protocol/web_app_endpoint.rb
Overview
Rack endpoint that serves the pre-built Flutter web app’s index.html.
The HTML is read from build_dir and returned as-is — no mutation. The backend URL is baked into the build at compile time via:
rake ruflet:build[web] # reads backend_url from ruflet.yaml
which passes –dart-define=RUFLET_URL=<backend_url> to flutter build. The Flutter client reads it via String.fromEnvironment(‘RUFLET_URL’).
Static assets (JS, WASM, fonts) in the build dir are served by Rails’ ActionDispatch::Static as normal.
Usage in routes.rb:
match "/ws", to: Ruflet::Rails.app(Rails.root.join("app/views/mobile/main.rb")), via: :all
get "/showcase", to: Ruflet::Rails.web(build: Rails.root.join("public/showcase"))
Instance Method Summary collapse
- #call(_env) ⇒ Object
-
#initialize(build_dir:) ⇒ WebAppEndpoint
constructor
A new instance of WebAppEndpoint.
Constructor Details
#initialize(build_dir:) ⇒ WebAppEndpoint
Returns a new instance of WebAppEndpoint.
25 26 27 |
# File 'lib/ruflet/rails/protocol/web_app_endpoint.rb', line 25 def initialize(build_dir:) @index_path = File.join(build_dir.to_s, "index.html") end |
Instance Method Details
#call(_env) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ruflet/rails/protocol/web_app_endpoint.rb', line 29 def call(_env) return not_found unless File.file?(@index_path) html = File.read(@index_path) [200, { "content-type" => "text/html; charset=utf-8", "content-length" => html.bytesize.to_s }, [html]] end |