Class: Server

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

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



21
22
23
24
# File 'lib/volt/server.rb', line 21

def initialize
  @app_path = File.expand_path(File.join(Dir.pwd, "app"))
  @component_paths = ComponentPaths.new
end

Instance Method Details

#appObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/volt/server.rb', line 26

def app
  @app = Rack::Builder.new
  @app.use Rack::CommonLogger
  @app.use Rack::ShowExceptions

  component_paths = @component_paths
  @app.map '/components' do
    run ComponentHandler.new(component_paths)
  end
  
  # Serve the opal files
  OpalFiles.new(@app, @app_path, @component_paths)

  # Serve the main html files from public, also figure out
  # which JS/CSS files to serve.
  @app.use IndexFiles, @component_paths
  
  # Handle socks js connection
  if RUBY_PLATFORM != 'java'
    @app.map "/channel" do
      run Rack::SockJS.new(ChannelHandler)#, :websocket => false
    end
  end
  
  @app.use Rack::Static,
    :urls => ["/"],
    :root => "public",
    :index => "",
    :header_rules => [
      [:all, {'Cache-Control' => 'public, max-age=86400'}]
    ]

  @app.run lambda{ |env| [ 404, { 'Content-Type'  => 'text/html' }, ['404 - page not found'] ] }
  
  return @app
end