Module: GRHttp::Base::Rack

Defined in:
lib/grhttp/rack_support.rb

Class Method Summary collapse

Class Method Details

.call(request, response) ⇒ Object


27
28
29
30
31
32
33
34
# File 'lib/grhttp/rack_support.rb', line 27

def call request, response
	if tmp = request[:io].params[:pre_rack_handler]
		tmp = tmp.call(request, response)
		return tmp if tmp
	end
	# response.quite!
	response.run_rack @app
end

.run(app, options = {}) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/grhttp/rack_support.rb', line 7

def run(app, options = {})
	@app = app			
	add = true
	(GReactor.instance_variable_get(:@listeners) || {}).each do |params, io|
		# if this is the first listener with a default port - update the port number
		params[:port] = options[:Port] if params[:port] == 3000 && add
		params[:pre_rack_handler] = params[:http_handler]
		params[:http_handler] = self
		add = false
	end

	GRHttp.listen port: options[:Port], bind: options[:Host], http_handler: self if add

	GReactor.log_raw "\r\nStarting GRHttp v. #{GRHttp::VERSION} on GReactor #{GReactor::VERSION}.\r\n"
	GReactor.log_raw "\r\nUse ^C to exit\r\n"

	GReactor.start
	GReactor.join {GReactor.log_raw "\r\nGRHttp and GReactor starting shutdown\r\n"}
	GReactor.log_raw "\r\nGRHttp and GReactor completed shutdown\r\n"
end