Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 09e6108020d8f232662de10e3cc10b5664539f76 @rwdaigle committed Jun 2, 2011
Showing with 102 additions and 0 deletions.
  1. +1 −0 .rvmrc
  2. +6 −0 Gemfile
  3. +60 −0 Gemfile.lock
  4. +1 −0 Procfile
  5. +2 −0 README
  6. +32 −0 hello.rb
1 .rvmrc
@@ -0,0 +1 @@
+rvm use ruby-1.9.2@demo.goliath --create
@@ -0,0 +1,6 @@
+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'
@@ -0,0 +1,60 @@
+GIT
+ remote: git://github.com/igrigorik/em-http-request.git
+ revision: ba1c1a3f34cb80c4bf4a49596238472f44e84522
+ specs:
+ em-http-request (1.0.0.beta.4)
+ addressable (>= 2.2.3)
+ em-socksify
+ eventmachine (>= 1.0.0.beta.3)
+ http_parser.rb (>= 0.5.1)
+
+GIT
+ remote: git://github.com/igrigorik/em-synchrony.git
+ revision: 5c2aa0ec22509102a1e2fda659c1d2cea5cb6d5e
+ specs:
+ em-synchrony (0.3.0.beta.1)
+ eventmachine (>= 1.0.0.beta.1)
+
+GIT
+ remote: git://github.com/postrank-labs/goliath.git
+ revision: ca799a9cccc94eece879336e97439d7a57a7ea3b
+ specs:
+ goliath (0.9.1)
+ async-rack
+ em-synchrony (>= 0.3.0.beta.1)
+ eventmachine (>= 1.0.0.beta.3)
+ http_parser.rb
+ log4r
+ multi_json
+ rack (>= 1.2.2)
+ rack-contrib
+ rack-respond_to
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ addressable (2.2.6)
+ async-rack (0.5.1)
+ rack (~> 1.1)
+ em-socksify (0.1.0)
+ eventmachine
+ eventmachine (1.0.0.beta.3)
+ http_parser.rb (0.5.1)
+ log4r (1.1.9)
+ multi_json (1.0.3)
+ rack (1.3.0)
+ rack-accept-media-types (0.9)
+ rack-contrib (1.1.0)
+ rack (>= 0.9.1)
+ rack-respond_to (0.9.8)
+ rack-accept-media-types (>= 0.6)
+ yajl-ruby (0.8.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ em-http-request!
+ em-synchrony!
+ goliath!
+ yajl-ruby
@@ -0,0 +1 @@
+web: bundle exec ruby hello.rb -sv -e prod -p $PORT
2 README
@@ -0,0 +1,2 @@
+Project to enable easy deployment of Ilya's Goliath async web server example to Heroku:
+http://www.igvita.com/2011/06/02/0-60-deploying-goliath-on-heroku-cedar/
@@ -0,0 +1,32 @@
+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
+

0 comments on commit 09e6108

Please sign in to comment.