Created
June 2, 2011 03:31
-
-
Save igrigorik/1003878 to your computer and use it in GitHub Desktop.
deploying Goliath on Heroku's cedar stack
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 :gemcutter | |
gem 'goliath', :git => 'git://github.com/postrank-labs/goliath.git' | |
gem 'em-http-request', :git => 'git://github.com/igrigorik/em-http-request.git' | |
gem 'em-synchrony', :git => 'git://github.com/igrigorik/em-synchrony.git' | |
gem 'yajl-ruby' |
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 'goliath' | |
require 'em-synchrony/em-http' | |
require 'em-http/middleware/json_response' | |
require 'yajl' | |
# automatically parse the JSON HTTP response | |
EM::HttpRequest.use EventMachine::Middleware::JSONResponse | |
class Hello < Goliath::API | |
# parse query params and auto format JSON response | |
use Goliath::Rack::Params | |
use Goliath::Rack::Formatters::JSON | |
use Goliath::Rack::Render | |
def response(env) | |
resp = nil | |
if params['query'] | |
# simple GitHub API proxy example | |
logger.info "Starting request for #{params['query']}" | |
conn = EM::HttpRequest.new("http://github.com/api/v2/json/repos/search/#{params['query']}").get | |
logger.info "Received #{conn.response_header.status} from Github" | |
resp = conn.response | |
else | |
resp = env # output the Goalith environment | |
end | |
[200, {'Content-Type' => 'application/json'}, resp] | |
end | |
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
web: bundle exec ruby hello.rb -sv -e prod -p $PORT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment