Created
November 12, 2012 05:44
-
-
Save datenimperator/4057694 to your computer and use it in GitHub Desktop.
Sinatra deferred reaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
require './lib/poi_api.rb' | |
map '/' do | |
run PoiApi::App | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
# Specify your gem's dependencies in poi_api.gemspec | |
gem 'rack' | |
gem 'sinatra' | |
gem 'shotgun' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'sinatra/base' | |
module PoiApi | |
class App < Sinatra::Base | |
configure :production, :development do | |
enable :logging | |
end | |
before do | |
content_type :json | |
end | |
get '/analytics' do | |
logger.info "Before" | |
late do | |
puts "Yehi!" | |
end | |
logger.info "After" | |
"Yes!" | |
end | |
private | |
def late(&block) | |
Thread.new do | |
sleep 0.5 | |
block.call | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment