-
Notifications
You must be signed in to change notification settings - Fork 36
/
config.ru
88 lines (68 loc) · 1.55 KB
/
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'bundler'
Bundler.require
apps = []
require 'opal/rspec'
Opal::Config.arity_check_enabled = true
Opal::Config.enable_source_location = true if Opal::Config.respond_to? :enable_file_source_location=
Opal::Config.enable_file_source_embed = true if Opal::Config.respond_to? :enable_file_source_embed=
Opal.append_path "#{__dir__}/spec"
apps << Opal::SimpleServer.new do |s|
require_relative './spec/browser_runner_compat'
$locator = Opal::RSpec::Locator.new(
pattern: 'spec/**/*_spec.{rb,opal}',
default_path: 'spec'
)
s.index_path = 'spec/browser_runner_index.html.erb'
end
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
post '/http-file' do
if params['lol'] == 'wut' &&
params['file'][:filename] == 'yay.txt' &&
params['file'][:tempfile].read == 'content'
"ok"
else
"fail"
end
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.reverse)