Created
March 4, 2010 16:21
-
-
Save henrypoydar/321846 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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