#! /usr/bin/env ruby # # Simple script for staticifying your Rack applications # # Checks for config.ru / Rails by defualt, otherwise you can: # # $ staticify -r myapp.rb --app 'lambda {|env| [200, {}, "hi!"] }' info # $ staticify -r myapp.rb,another-file.rb --app 'Sinatra::Application' get '/' # $ staticify -r myapp --app 'MyApp.new' '/' # %w( rubygems rackbox optparse fileutils ).each {|lib| require lib } require File.dirname(__FILE__) + '/../lib/rack-staticifier' def usage puts < ex puts "Tried running Ruby code to set Rack app: #{ ruby_to_run.inspect }" raise ex end end unless RackBox.app(:silent => true) puts "Cannot find your Rack application\n\n" usage exit end #### ==== Get Routes to Cache ==== #### paths_to_cache = [] while path = gets paths_to_cache << path.strip end puts "Caching to #{ path_to_cache_to }" puts "#{ paths_to_cache.length } paths to cache:" #### ==== Cache the Routes ==== ####" FileUtils.rm_rf path_to_cache_to RackBox.app = Rack::Staticifier.new(RackBox.app, :root => path_to_cache_to) paths_to_cache.each do |path| response = RackBox.request path puts " #{ response.status } #{ path }" end