Class: FactoryBurgers::Middleware::Static
- Inherits:
-
Object
- Object
- FactoryBurgers::Middleware::Static
- Defined in:
- lib/factory_burgers/middleware/static.rb
Overview
Serve static assets build for the UI
Instance Method Summary collapse
- #asset_path ⇒ Object
- #call(env) ⇒ Object
- #rack_static ⇒ Object
- #slashpath_redirect(path) ⇒ Object
- #slashpath_redirect?(env) ⇒ Boolean
- #static_options ⇒ Object
Instance Method Details
#asset_path ⇒ Object
31 32 33 |
# File 'lib/factory_burgers/middleware/static.rb', line 31 def asset_path @asset_path ||= FactoryBurgers.root.join("assets/") end |
#call(env) ⇒ Object
5 6 7 8 9 |
# File 'lib/factory_burgers/middleware/static.rb', line 5 def call(env) return slashpath_redirect(env["REQUEST_PATH"]) if slashpath_redirect?(env) rack_static.call(env) end |
#rack_static ⇒ Object
23 24 25 |
# File 'lib/factory_burgers/middleware/static.rb', line 23 def rack_static Rack::Static.new(nil, ) end |
#slashpath_redirect(path) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/factory_burgers/middleware/static.rb', line 15 def slashpath_redirect(path) return [ 302, {'Location' => "#{path}/", 'Content-Type' => 'text/html', 'Content-Length' => '0'}, [], ] end |
#slashpath_redirect?(env) ⇒ Boolean
11 12 13 |
# File 'lib/factory_burgers/middleware/static.rb', line 11 def slashpath_redirect?(env) env["REQUEST_PATH"] == env["SCRIPT_NAME"] && env["REQUEST_PATH"][-1] != "/" end |
#static_options ⇒ Object
27 28 29 |
# File 'lib/factory_burgers/middleware/static.rb', line 27 def {urls: [""], root: asset_path, index: 'index.html'} end |