Class: Genesis::Http::Server

Inherits:
Sinatra::Base
  • Object
show all
Includes:
Protocol, Server
Defined in:
lib/genesis/protocol/http/server.rb

Overview

Implement an HTTP server using async_sinatra and thin

Instance Attribute Summary

Attributes included from Server

#channel, #handle_routes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Protocol

included

Methods included from Server

included

Constructor Details

#initialize(app = nil, **kwargs) ⇒ Server

Inject the channel and extended routes



34
35
36
37
38
39
40
# File 'lib/genesis/protocol/http/server.rb', line 34

def initialize(app = nil, **kwargs)
  super(app)
  @channel = kwargs[:channel] || nil
  @extended_routes = kwargs[:routes] || {}
  @views = kwargs[:views] || []
  initialize_routes
end

Class Method Details

.start_serverObject

Block to actually start the server



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/genesis/protocol/http/server.rb', line 18

def self.start_server
  app = new(channel: @channel, routes: @handle_routes, views: @args[:views] || [])
  dispatch = Rack::Builder.app do
    map '/' do
      run app
    end
  end

  # Enable full request logging with @debug
  Thin::Logging.trace=true if @args[:debug]
  # Since Thin is backed by EventMachine's TCPserver anyways,
  # This is just a TCPServer like any other - running inside the same EventMachine!
  Thin::Server.new(@port, '0.0.0.0', dispatch).backend.start
end