Sinatra Modular app not recognizing routes on AppFog-Collection of common programming errors
I have started writing my Sinatra apps using a modular style, suggested in this stackoverflow answer, and have successfully deployed it on Heroku, but when trying to deploy to AppFog (identical code except for datamapper mysql/postgres gems) I get “Not Found” errors for every route I have defined.
== Sinatra/1.3.3 has taken the stage on 47195 for production with backup from Thin
myIP, 127.0.0.1 - - [08/Dec/2012 21:28:53] "GET / HTTP/1.0" 404 18 0.0030
myIP, 127.0.0.1 - - [08/Dec/2012 21:28:54] "GET /any_route HTTP/1.0" 404 18 0.0010
myIP, 127.0.0.1 - - [08/Dec/2012 21:28:58] "GET /about HTTP/1.0" 404 18 0.0008
My view and public paths from settings:
settings.views = "./views"
root = "."
settings.sin_auth_view_path = "/mnt/var/vcap.local/dea/apps/myapp-0-d1d1d1dc0e543b1759afda27b/app/views/"
public_folder = "./public"
An example of defined route:
class MyApp < Sinatra::Application
get '/' do
@title = "Site Index Page"
haml :index
end
end
Config.ru
require ::File.join( ::File.dirname(__FILE__), 'app')
run MyApp.new
Structure is basically identical to that linked to above.
There are no application errors, just the “Not Found” message and corresponding 404 “GET” entries in the logs. The PUBLIC folder is working as it should – I can access all static files off the site url (ie. site.com/img/anypic.jpg
). And, as I mentioned, the exact same app runs flawlessly on Heroku.
I am using bundle package, so a custom gem can be used, and had no problems until switching to the modular structure.
Installed on AppFog Ruby 1.9.3 Runtime.
Thoughts….
-
Thanks to a user on the AppFog Google User Group, the solution was to deploy as a Rack application instead of a Sinatra application.
Note: Also make sure to use the
--runtime ruby193
command line option, if you are usingrequire_relative
🙂 -
I would check to see if you might be having a problem with the “settings.sin_auth_view_path” entry as it’s an absolute path (whereas the other two are relative). Heroku does not have the normal filesystem layout that you’re used to seeing on a development box once you ascend outside your app’s source.