Created
August 11, 2014 09:02
-
-
Save karlentwistle/de8a5f90bd9274ffcfa1 to your computer and use it in GitHub Desktop.
Very Simple Rack TryStatic
This file contains hidden or 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
require 'rack' | |
class MyApp | |
def call env | |
[200, {"Content-Type" => "text/html"}, ["Hello Rack Participants"]] | |
end | |
end | |
class TryStatic | |
def initialize(app, options) | |
@app = app | |
@static = Rack::Static.new(@app, options) | |
end | |
def call(env) | |
rack_static_response = @static.call(env) | |
if rack_static_response[0] == 404 | |
@app.call(env) | |
else | |
rack_static_response | |
end | |
end | |
end | |
use TryStatic, :urls => ["/css"] | |
use TryStatic, :urls => ["/css"], :root => "/Users/karl/Desktop/test_rack/mha" | |
run MyApp.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This could be more performant.