Skip to content

Instantly share code, notes, and snippets.

@karlentwistle
Created August 11, 2014 09:02
Show Gist options
  • Save karlentwistle/de8a5f90bd9274ffcfa1 to your computer and use it in GitHub Desktop.
Save karlentwistle/de8a5f90bd9274ffcfa1 to your computer and use it in GitHub Desktop.
Very Simple Rack TryStatic
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
@karlentwistle
Copy link
Author

This could be more performant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment