Skip to content

Instantly share code, notes, and snippets.

@rgrove
Created April 20, 2010 20:56
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 rgrove/373063 to your computer and use it in GitHub Desktop.
Save rgrove/373063 to your computer and use it in GitHub Desktop.
Simple "right here, right now" web server for testing static content
# Install dependencies:
#
# gem install thin
#
# Run this to serve the current directory at http://localhost:3000/:
#
# thin -R /path/to/serve.ru start
#
require 'rubygems'
require 'rack'
require 'rack/commonlogger'
require 'rack/conditionalget'
require 'rack/deflater'
require 'rack/directory'
require 'rack/etag'
DIR = File.expand_path('.')
class NoCache
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers['Cache-Control'] = 'must-revalidate'
[status, headers, body]
end
end
class Cache
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers['Cache-Control'] = 'max-age=315360000'
headers['Expires'] = 'Fri, 01 May 2020 03:47:24 GMT'
[status, headers, body]
end
end
use Rack::CommonLogger
use Rack::ConditionalGet
use Rack::Deflater
use Rack::ETag
# Enable or disable caching as you wish.
use NoCache
# use Cache
map '/' do
run Rack::Directory.new(DIR)
puts "Serving all files under #{DIR}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment