Reloading Sinatra app on every request on Windows

Posted by Darth on Stack Overflow See other posts from Stack Overflow or by Darth
Published on 2009-12-17T12:08:50Z Indexed on 2010/04/07 0:03 UTC
Read the original article Hit count: 496

Filed under:
|
|
|

I've set up Rack::Reload according to this thread

# config.ru
require 'rubygems'
require 'sinatra'

set :environment, :development

require 'app'
run Sinatra::Application

# app.rb  
class Sinatra::Reloader < Rack::Reloader
  def safe_load(file, mtime, stderr = $stderr)
    if file == Sinatra::Application.app_file
      ::Sinatra::Application.reset!
      stderr.puts "#{self.class}: reseting routes"
    end
    super
  end
end

configure(:development) { use Sinatra::Reloader }

get '/' do
  'foo'
end

Running with thin via thin start -R config.ru, but it only reloads newly added routes. When I change already existing route, it still runs the old code.

When I add new route, it correctly reloads it, so it is accessible, but it doesn't reload anything else.

For example, if I changed routes to

get '/' do
  'bar'
end

get '/foo' do
  'baz'
end

Than / would still serve foo, even though it has changed, but /foo would correctly reload and serve baz.

Is this normal behavior, or am I missing something? I'd expect whole source file to be reloaded. The only way around I can think of right now is restarting whole webserver when filesystem changes.

I'm running on Windows Vista x64, so I can't use shotgun because of fork().

© Stack Overflow or respective owner

Related posts about ruby

Related posts about sinatra