2012-03-07 16:17:58 -05:00
|
|
|
$stderr.puts "loading"
|
2011-10-31 17:40:22 -04:00
|
|
|
require 'sinatra'
|
|
|
|
|
2011-11-05 09:46:14 -04:00
|
|
|
configure do
|
|
|
|
set :foo, :bar
|
|
|
|
end
|
|
|
|
|
2011-10-31 17:40:22 -04:00
|
|
|
get '/app_file' do
|
|
|
|
content_type :txt
|
|
|
|
settings.app_file
|
2011-11-05 09:46:14 -04:00
|
|
|
end
|
|
|
|
|
2012-03-07 16:17:58 -05:00
|
|
|
get '/ping' do
|
|
|
|
'pong'
|
|
|
|
end
|
|
|
|
|
2012-03-07 16:58:59 -05:00
|
|
|
get '/stream' do
|
|
|
|
stream do |out|
|
|
|
|
sleep 0.1
|
|
|
|
out << "a"
|
|
|
|
sleep 1.2
|
|
|
|
out << "b"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-05 09:46:14 -04:00
|
|
|
get '/mainonly' do
|
|
|
|
object = Object.new
|
|
|
|
begin
|
|
|
|
object.send(:get, '/foo') { }
|
|
|
|
'false'
|
|
|
|
rescue NameError
|
|
|
|
'true'
|
|
|
|
end
|
|
|
|
end
|
2012-03-07 16:17:58 -05:00
|
|
|
|
2012-03-08 03:57:08 -05:00
|
|
|
set :out, nil
|
|
|
|
get '/async' do
|
|
|
|
stream(:keep_open) { |o| (settings.out = o) << "hi!" }
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/send' do
|
|
|
|
settings.out << params[:msg] if params[:msg]
|
|
|
|
settings.out.close if params[:close]
|
|
|
|
"ok"
|
|
|
|
end
|
|
|
|
|
|
|
|
class Subclass < Sinatra::Base
|
|
|
|
set :out, nil
|
|
|
|
get '/subclass/async' do
|
2012-03-11 05:45:54 -04:00
|
|
|
stream(:keep_open) { |o| (settings.out = o) << "hi!" }
|
2012-03-08 03:57:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
get '/subclass/send' do
|
|
|
|
settings.out << params[:msg] if params[:msg]
|
|
|
|
settings.out.close if params[:close]
|
|
|
|
"ok"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
use Subclass
|
|
|
|
|
2012-03-07 16:17:58 -05:00
|
|
|
$stderr.puts "starting"
|