forked from opal/opal-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ru
64 lines (52 loc) · 960 Bytes
/
config.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'bundler'
Bundler.require
apps = []
apps << Opal::Server.new { |s|
s.append_path 'spec'
s.main = 'opal/rspec/sprockets_runner'
s.index_path = 'index.html.erb'
s.debug = false
}
apps << Class.new(Sinatra::Base) {
get '/http' do
"lol"
end
post '/http' do
if params['lol'] == 'wut'
"ok"
else
"fail"
end
end
put '/http' do
if params['lol'] == 'wut'
"ok"
else
"fail"
end
end
delete '/http' do
"lol"
end
get '/events' do
headers 'Content-Type' => 'text/event-stream'
stream do |out|
sleep 0.2
out << "data: lol\n" << "\n"
out << "event: custom\n" << "data: omg\n" << "\n"
out << "data: wut\n" << "\n"
sleep 10
end
end
get '/socket' do
request.websocket do |ws|
ws.onopen do
ws.send 'lol'
end
ws.onmessage do |msg|
ws.send msg
end
end
end
}
run Rack::Cascade.new(apps)