Class: N::Webrick

Inherits:
Object show all
Defined in:
lib/nitro/adapters/webrick.rb

Overview

Helper methods for the WebrickAdapter.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.serverObject

Returns the value of attribute server.



33
34
35
# File 'lib/nitro/adapters/webrick.rb', line 33

def server
  @server
end

Class Method Details

.start(conf) ⇒ Object



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
62
63
64
65
66
67
# File 'lib/nitro/adapters/webrick.rb', line 35

def start(conf)
	conf = Flexob.new(conf) unless conf.is_a?(Flexob)
	
	# patch for OSX
	
	Socket.do_not_reverse_lookup = true

	if :none == conf.log and RUBY_PLATFORM !~ /mswin32/
		accesslog = WEBrick::BasicLog::new('/dev/null')
		refererlog = WEBrick::BasicLog::new('/dev/null')	
	elsif (conf.accesslog || conf.refererlog)
		accesslog = WEBrick::BasicLog::new(conf.accesslog || 'log/access.log')
		refererlog = WEBrick::BasicLog::new(conf.refererlog || 'log/referer.log')	
	else
		accesslog = STDERR
		refererlog = STDERR
	end
	
	@server = WEBrick::HTTPServer.new(
		:BindAddress => conf.host, 
		:Port => conf.port, 
		:DocumentRoot => conf.dispatcher.root,
		:AccessLog => [
			[accesslog, WEBrick::AccessLog::COMMON_LOG_FORMAT],
			[refererlog, WEBrick::AccessLog::REFERER_LOG_FORMAT]
		]
	)
	
	trap('INT') { @server.shutdown }

	@server.mount('/', WebrickAdapter, conf)
	@server.start
end