Skip to content

Instantly share code, notes, and snippets.

@zeeshanlakhani
Forked from igrigorik/Gemfile
Created January 13, 2012 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeeshanlakhani/1604959 to your computer and use it in GitHub Desktop.
Save zeeshanlakhani/1604959 to your computer and use it in GitHub Desktop.
deploying Goliath on Heroku's cedar stack
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'
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
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