Class: Titanium::Server

Inherits:
Base
  • Object
show all
Includes:
Rack::Utils
Defined in:
lib/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Server

Constructs a new Application. This effectively starts the entire web server process which also includes initializing all other downstream processes such as the database layer.



32
33
34
35
36
37
# File 'lib/server.rb', line 32

def initialize(root)
  @app_root = root
  @file_server = Rack::File.new(@app_root)
  erase_db if Configuration.clean_start
  start_db
end

Instance Method Details

#call(env) ⇒ Object

Handles the Rack request.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/server.rb', line 65

def call(env) 
  begin   
    create_rack_request(env)
    if is_valid_request?
      if is_static_request?
        serve_static_request
      else
        serve_dynamic_request
      end
    else
      serve_bad_request
    end
  rescue Exception => ex
    log_error(ex)
    serve_internal_server_error
  end
end

#erase_dbObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/server.rb', line 39

def erase_db
  db_instance = Configuration.db_adapter.new
  begin
    db_instance.erase_db
  rescue Exception => ex
    log_error(ex)
    return nil
  ensure
    db_instance.disconnect
  end
end

#start_dbObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/server.rb', line 51

def start_db
  db_instance = Configuration.db_adapter.new
  begin
    db_instance.connect
    db_instance.startup
  rescue Exception => ex
    log_error(ex)
    return nil
  ensure
    db_instance.disconnect
  end
end