Skip to content

Instantly share code, notes, and snippets.

@henrypoydar
Created March 4, 2010 16:21
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 henrypoydar/321846 to your computer and use it in GitHub Desktop.
Save henrypoydar/321846 to your computer and use it in GitHub Desktop.
# Rack middleware for serving individual javascript files
# from non-public directories to the Jammit asset packager
# when in test or development modes
#
# To use, add this line to the relevant (development)
# environment file:
#
# config.middleware.use 'JavascriptsHost'
#
class JavascriptsHost
def initialize(app, opts={})
@app = app
@location = opts[:location] || '/app/javascripts'
root = opts[:root] || Dir.pwd
@file_server = Rack::File.new(root)
end
def call(env)
path = env["PATH_INFO"]
if path.index(@location) == 0
resp = @file_server.call(env)
return resp unless resp[0] == 404
end
@app.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment