Sinatra doesn't know this ditty even when default route is implemented with modular style

nikhil picture nikhil · Jan 18, 2015 · Viewed 8.1k times · Source

I'm running MacOS mavericks whith jruby and am trying to write a basic modular sinatra app. Here's what my config.ru looks like

require 'app/app'   
run Sinatra::Application

I invoke it like this with rackup, you can see the 404 errors -

rackup -s puma -p 8080
Puma 2.10.2 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:8080
127.0.0.1 - - [17/Jan/2015:18:32:37 -0500] "GET / HTTP/1.1" 404 437 0.0290
127.0.0.1 - - [17/Jan/2015:18:32:37 -0500] "GET / HTTP/1.1" 404 437 0.0980
127.0.0.1 - - [17/Jan/2015:18:32:37 -0500] "GET /__sinatra__/404.png HTTP/1.1" 304 - 0.0120
127.0.0.1 - - [17/Jan/2015:18:32:37 -0500] "GET /__sinatra__/404.png HTTP/1.1" 304 - 0.0170

and this is what my source looks like -

➜ less app/app.rb
require 'sinatra/base'

class App < Sinatra::Base

  get '/' do
    "Hello World"
  end
end

If I change the source to the classic way

➜ cat app/app.rb
require 'sinatra'

#class App < Sinatra::Base

  get '/' do
    "Hello World"
  end
#end

and then invoke it like this, it works just fine -

➜ ruby app/app.rb
Puma 2.10.2 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:4567
== Sinatra/1.4.5 has taken the stage on 4567 for development with backup from Puma
127.0.0.1 - - [17/Jan/2015:18:36:20 -0500] "GET / HTTP/1.1" 200 11 0.0250

I think I'm missing some very obvious config but can seem to figure out what that is, can someone let me know what I am missing? I can share more details about the environment if they are so required.

Answer

matt picture matt · Jan 18, 2015

When you use the modular style, the Sinatra::Application app still exists, but usually nothing happens to it. In your config.ru you are running this (empty) app instead of your own. Simply change run Sinatra::Application to

run App