Skip to content

Commit

Permalink
adding an ENV variable GOLIATH_ENV to make server env agnostic
Browse files Browse the repository at this point in the history
swap out /v1/users in favor of /v1/categories
bundle update :
+++ b/Gemfile.lock
+    addressable (2.3.2)
+    em-websocket (0.3.8)
+      addressable (>= 2.1.1)
+      eventmachine (>= 0.12.9)
+    goliath (1.0.0)
+      em-websocket
+      eventmachine (>= 1.0.0.beta.4)
+      http_parser.rb (= 0.5.3)
  • Loading branch information
lgs committed Aug 12, 2012
1 parent 1b6c2a8 commit 894e962
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
17 changes: 8 additions & 9 deletions Gemfile.lock
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.3.2)
async-rack (0.5.1)
rack (~> 1.1)
bson (1.6.4)
Expand All @@ -11,13 +12,16 @@ GEM
eventmachine (>= 0.12.10)
em-synchrony (1.0.2)
eventmachine (>= 1.0.0.beta.1)
em-websocket (0.3.8)
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
eventmachine (1.0.0.rc.4)
goliath (0.9.4)
goliath (1.0.0)
async-rack
em-synchrony (>= 1.0.0)
eventmachine (>= 1.0.0.beta.3)
http_parser.rb
http_router (~> 0.9.0)
em-websocket
eventmachine (>= 1.0.0.beta.4)
http_parser.rb (= 0.5.3)
log4r
multi_json
rack (>= 1.2.2)
Expand All @@ -31,9 +35,6 @@ GEM
rack-mount
hashie (1.2.0)
http_parser.rb (0.5.3)
http_router (0.9.7)
rack (>= 1.0.0)
url_mount (~> 0.2.1)
log4r (1.1.10)
mongo (1.6.4)
bson (~> 1.6.4)
Expand All @@ -47,8 +48,6 @@ GEM
rack (>= 1.0.0)
rack-respond_to (0.9.8)
rack-accept-media-types (>= 0.6)
url_mount (0.2.1)
rack

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion Procfile
@@ -1,2 +1,2 @@
web: bundle exec ruby app.rb -sv -e prod -p $PORT
web: bundle exec ruby app.rb -sv -e $GOLIATH_ENV -p $PORT

20 changes: 11 additions & 9 deletions app.rb
Expand Up @@ -8,21 +8,23 @@ class API < Grape::API
version 'v1', :using => :path
format :json

resource 'users' do

# http://0.0.0.0:9000/v1/users/

#resource 'users' do
# # http://0.0.0.0:9000/v1/users/
# get "/" do
# coll = env.mongo.collection('users') #Connection Pool from Goliath ENV
# coll.find({})
# end
#end

resource 'categories' do
# http://0.0.0.0:9000/v1/categories/
get "/" do
coll = env.mongo.collection('users') #Connection Pool from Goliath ENV
coll = env.mongo.collection('categories') #Connection Pool from Goliath ENV
coll.find({})
end

end

end



class App < Goliath::API
def response(env)
API.call(env)
Expand Down
29 changes: 17 additions & 12 deletions config/app.rb
@@ -1,15 +1,20 @@
#this should live in a file called app.rb inside a directory called 'config'

#config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do
# conn = EM::Mongo::Connection.new('localhost', 27017, 1, {:reconnect_in => 1})
# conn.db('db')
#nd

config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do
mongolab = URI.parse(ENV['MONGOLAB_URI'])
conn = EM::Mongo::Connection.new mongolab.host, mongolab.port, 1, {:reconnect_in => 1}

db = conn.db mongolab.path.gsub(/^\//, '')
db.authenticate mongolab.user, mongolab.password
db
environment :development do
config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do
conn = EM::Mongo::Connection.new('localhost', 27017, 1, {:reconnect_in => 1})
conn.db('db')
end
end

environment :production do
config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do
mongolab = URI.parse(ENV['MONGOLAB_URI'])
conn = EM::Mongo::Connection.new mongolab.host, mongolab.port, 1, {:reconnect_in => 1}

db = conn.db mongolab.path.gsub(/^\//, '')
db.authenticate mongolab.user, mongolab.password
db
end
end

0 comments on commit 894e962

Please sign in to comment.