Skip to content

Commit a7ddbdb

Browse files
author
David Padilla
committed
Add the server_rails.rb file that does the same example
with the Rails app
1 parent 8ef2a4d commit a7ddbdb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Diff for: rack/server_rails.rb

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
$: << '../rails/app'
2+
3+
require 'eventmachine'
4+
require 'thin'
5+
require 'config/environment'
6+
7+
module Server
8+
def receive_data(data)
9+
request = Thin::Request.new
10+
request.parse(data)
11+
12+
app = Rails.application
13+
14+
status, headers, body = app.call(request.env)
15+
16+
response = "HTTP/1.1 #{status} OK\r\n"
17+
18+
headers.each do |h,v|
19+
response << "#{h}: #{v}\r\n"
20+
end
21+
22+
response << "\r\n"
23+
body.each do |b|
24+
response << "#{b}\r\n"
25+
end
26+
27+
send_data response
28+
close_connection true
29+
end
30+
end
31+
32+
EventMachine.run do
33+
EventMachine.start_server "0.0.0.0", 9292, Server
34+
end

0 commit comments

Comments
 (0)