Class: Hanami::Static Private
- Inherits:
-
Rack::Static
- Object
- Rack::Static
- Hanami::Static
- Defined in:
- lib/hanami/static.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Serve static assets in deployment environments (production, staging) where the stack doesn’t include a web server.
Web servers like Nginx are the ideal candidate to serve static assets. They are faster than Ruby application servers (eg. Puma) and they should be always preferred for this specific task.
But there are some PaaS that don’t allow to use web servers in front of Ruby web applications. A classical example is Heroku, which requires the web application to serve static assets.
Hanami::Static is designed for this specific scenario.
To enable it set the env variable ‘SERVE_STATIC_ASSETS` on `true`.
NOTE: Please remember to precompile the assets at the deploy time with ‘bundle exec hanami assets precompile`.
Direct Known Subclasses
Constant Summary collapse
- MAX_AGE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
60 * 60 * 24 * 365
- HEADER_RULES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[[:all, { 'Cache-Control' => "public, max-age=#{MAX_AGE}" }]].freeze
- URL_PREFIX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'/'.freeze
Instance Method Summary collapse
-
#initialize(app, root: Hanami.public_directory, header_rules: HEADER_RULES) ⇒ Static
constructor
private
A new instance of Static.
Constructor Details
#initialize(app, root: Hanami.public_directory, header_rules: HEADER_RULES) ⇒ Static
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Static.
41 42 43 |
# File 'lib/hanami/static.rb', line 41 def initialize(app, root: Hanami.public_directory, header_rules: HEADER_RULES) super(app, urls: _urls(root), root: root, header_rules: header_rules) end |