Class: Athar::Middleware::AssetServer
- Inherits:
-
Object
- Object
- Athar::Middleware::AssetServer
- Defined in:
- lib/athar/middleware/asset_server.rb
Overview
Serves Athar’s dashboard assets (‘dashboard.js`, `dashboard.css`) directly to hosts that don’t have an asset pipeline configured. Rails apps with Sprockets or Propshaft never reach this middleware — the layout helper resolves to a digested asset path served by the asset pipeline.
The URL embeds Athar::VERSION as a cache-busting prefix (‘/athar-assets/<version>/dashboard.js`); the version segment is stripped before resolving to disk so a single canonical file lives in `app/assets/`. New gem version → new URL → fresh cache.
Constant Summary collapse
- PREFIX_PATTERN =
%r{\A/athar-assets/[^/]+/(.+)\z}- MIME_TYPES =
{ ".js" => "application/javascript", ".css" => "text/css" }.freeze
- EXTENSION_DIRS =
Where each file extension lives, relative to the engine root.
{ ".js" => "app/assets/javascripts/athar", ".css" => "app/assets/stylesheets/athar" }.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, engine_root) ⇒ AssetServer
constructor
A new instance of AssetServer.
Constructor Details
#initialize(app, engine_root) ⇒ AssetServer
Returns a new instance of AssetServer.
28 29 30 31 |
# File 'lib/athar/middleware/asset_server.rb', line 28 def initialize(app, engine_root) @app = app @root = File.(engine_root.to_s) end |
Instance Method Details
#call(env) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/athar/middleware/asset_server.rb', line 33 def call(env) path = env["PATH_INFO"].to_s match = PREFIX_PATTERN.match(path) return @app.call(env) unless match file = resolve(match[1]) return not_found unless file [200, response_headers(file), [File.binread(file)]] end |