Class: Volt::DefaultMiddlewareStack

Inherits:
Object
  • Object
show all
Defined in:
lib/volt/server/middleware/default_middleware_stack.rb

Class Method Summary collapse

Class Method Details

.postboot_setup(volt_app, rack_app) ⇒ Object

Setup the middleware that we need to wait for components to boot before we can set them up.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/volt/server/middleware/default_middleware_stack.rb', line 41

def self.postboot_setup(volt_app, rack_app)
  component_paths = volt_app.component_paths
  rack_app.map '/components' do
    run ComponentHandler.new(component_paths)
  end

  # Serve the opal files
  opal_files = OpalFiles.new(rack_app, volt_app.app_path, volt_app.component_paths)
  volt_app.sprockets = opal_files.environment

  # Serve the main html files from public, also figure out
  # which JS/CSS files to serve.
  rack_app.use IndexFiles, volt_app, volt_app.component_paths, opal_files

  rack_app.use HttpResource, volt_app, volt_app.router

  rack_app.use Rack::Static,
                urls: ['/'],
                root: 'config/base',
                index: '',
                header_rules: [
                  [:all, { 'Cache-Control' => 'public, max-age=86400' }]
                ]

  rack_app.run lambda { |env| [404, { 'Content-Type' => 'text/html; charset=utf-8' }, ['404 - page not found']] }
end

.preboot_setup(volt_app, rack_app) ⇒ Object

Setup on the middleware we can setup before booting components



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/volt/server/middleware/default_middleware_stack.rb', line 15

def self.preboot_setup(volt_app, rack_app)
  # Should only be used in production
  if Volt.config.deflate
    rack_app.use Rack::Deflater
    rack_app.use Rack::Chunked
  end

  rack_app.use Rack::ContentLength
  rack_app.use Rack::KeepAlive
  rack_app.use Rack::ConditionalGet
  rack_app.use Rack::ETag

  rack_app.use Rack::Session::Cookie, {
    :key => 'rack.session',
    # :domain => 'localhost.com',
    :path => '/',
    :expire_after => 2592000,
    :secret => Volt.config.app_secret
  }

  rack_app.use QuietCommonLogger
  rack_app.use Rack::ShowExceptions
end