Class: Ape::Server

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

Overview

Manages and initializes the Mongrel handler. See run for more details.

Class Method Summary collapse

Class Method Details

.run(options) ⇒ Object

Starts the Mongrel handler with options given in options and maps the /, /ape and /atompub/go URIs to handlers.

Options

* :host - the IP address to bind to
* :port - the port number to listen on
* :directory - the ape home directory


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ape/server.rb', line 18

def self.run(options)      
  Ape.home = options[:home]
  
  mongrel = Mongrel::Configurator.new(:host => options[:host], :port => options[:port]) do
    log "=> Booting mongrel"
    begin
      log "=> The ape starting on http://#{options[:host]}:#{options[:port]}"
      listener do
        redirect '/', '/web/index.html'
        uri '/web', :handler => 
          Mongrel::DirHandler.new(
            File.expand_path(File.dirname(__FILE__) + '/../../web'), true)
        uri '/atompub/go', :handler => Handler.new
      end
    rescue Errno::EADDRINUSE
      log "ERROR: Address (#{options[:host]}:#{options[:port]}) is already in use"
      exit 1
    end
    trap("INT") { stop }
    trap("TERM") { stop }
    log "=> Ctrl-C to shutdown"
    run
  end
  mongrel.join
end