-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ru
47 lines (42 loc) · 884 Bytes
/
server.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
43
44
45
46
47
$eventmachine_library = :pure_ruby
require 'em/pure_ruby'
puts EM.library_type
class Runtime
def initialize(app, name = nil)
@app = app
@header_name = "X-Runtime"
@header_name << "-#{name}" if name
end
def call(env)
r = Rack::Request.new(env)
puts r.url
status, headers, body = @app.call(env)
[status, headers, body]
end
end
file = File.read('index.html')
app = proc do |env|
r = Rack::Request.new(env)
if r.path == '/'
tmpl = file
content_type = 'text/html'
else
sleep 1
content_type = 'application/json'
tmpl = '{"hello":"world"}'
end
[
200,
{
'Content-Type' => content_type,
'Content-Length' => tmpl.size.to_s,
},
[tmpl]
]
end
# You can install Rack middlewares
# to do some crazy stuff like logging,
# filtering, auth or build your own.
use Runtime
use Rack::CommonLogger
run app