Skip to content

Instantly share code, notes, and snippets.

@rcreasey
Created August 12, 2011 23:19
Show Gist options
  • Select an option

  • Save rcreasey/1143207 to your computer and use it in GitHub Desktop.

Select an option

Save rcreasey/1143207 to your computer and use it in GitHub Desktop.
EM-Mongo and Goliath
config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do
conn = EM::Mongo::Connection.new('localhost', 27017, 1, {:reconnect_in => 1})
conn.db('analytics')
end
class DbReader < Goliath::API
use Goliath::Rack::Params
use Goliath::Rack::Render, 'json'
use Goliath::Rack::JSONP
use Goliath::Rack::Validation::RequestMethod, %w(GET)
def response(env)
payload = {:results => database.collection('requests').find({}).to_a}
[200, {}, payload.to_json]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment