Skip to content

Instantly share code, notes, and snippets.

@lusis
Created April 14, 2011 21:06
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 lusis/920552 to your computer and use it in GitHub Desktop.
Save lusis/920552 to your computer and use it in GitHub Desktop.

local-app.rb

The local copy of the app.rb (with appropriate REDIS_URL changes) works fine with this invocation:

bundle exec ruby ./app.rb

When deploying to cfoundry, my main view and all of my routes are broken (404s)

I snagged the startup invocation from here:

https://github.com/cloudfoundry/vcap/blob/master/cloud_controller/staging/sinatra/plugin.rb#L21

Noah is a modular sinatra app inheriting from SinatraBase. All the routes are imported in the main app file:

https://github.com/lusis/Noah/blob/master/lib/noah/app.rb

When I deploy to Heroku, for instance, I use a rackup file like so:

require 'rubygems'
require 'sinatra'
require 'noah'
ENV['REDIS_URL'] = "<my openredis url>"
noah = Noah::App.new do
  set :run, false
  set :environment, :production
end  
run noah

The Gemfile just has one gem required - 'noah'

require 'rubygems'
require 'bundler/setup'
require 'thin'
require 'noah'
require 'json'
vcap_services = JSON.load(ENV['VCAP_SERVICES'])
redis_host = vcap_services["redis-2.2"][0]["credentials"]["hostname"]
redis_port = vcap_services["redis-2.2"][0]["credentials"]["port"]
redis_password = vcap_services["redis-2.2"][0]["credentials"]["password"]
app_ip = vcap_services['VMC_APP_HOST']
app_port = vcap_services['VMC_APP_PORT']
ENV['REDIS_URL'] = "redis://#{redis_password}@#{redis_host}:#{redis_port}/0"
Noah::App.run!
require 'rubygems'
require 'bundler/setup'
require 'thin'
require 'noah'
require 'json'
#vcap_services = JSON.load(ENV['VCAP_SERVICES'])
#redis_host = vcap_services["redis-2.2"][0]["credentials"]["hostname"]
#redis_port = vcap_services["redis-2.2"][0]["credentials"]["port"]
#redis_password = vcap_services["redis-2.2"][0]["credentials"]["password"]
#app_ip = vcap_services['VMC_APP_HOST']
#app_port = vcap_services['VMC_APP_PORT']
#ENV['REDIS_URL'] = "redis://#{redis_password}@#{redis_host}:#{redis_port}/0"
Noah::App.run!
require 'sinatra'
require 'rack'
require 'noah'
vcap_services = JSON.load(ENV['VCAP_SERVICES'])
redis_host = vcap_services["redis-2.2"][0]["credentials"]["hostname"]
redis_port = vcap_services["redis-2.2"][0]["credentials"]["port"]
redis_password = vcap_services["redis-2.2"][0]["credentials"]["password"]
app_ip = vcap_services['VMC_APP_HOST']
app_port = vcap_services['VMC_APP_PORT']
ENV['REDIS_URL'] = "redis://#{redis_password}@#{redis_host}:#{redis_port}/0"
server = ::Rack::Server.new()
server.instance_variable_set('@app', Noah::App.new )
server.instance_variable_set('@server', 'thin')
server.start
@lusis
Copy link
Author

lusis commented Apr 14, 2011

The updated-app.rb works. Getting auth issues with redis but that's okay for now.

@derekcollison
Copy link

That's good news..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment