Permalink
Browse files

try a new heroku setup

  • Loading branch information...
1 parent 2849e52 commit 5239296c8b5a7f95a12fe7573574530520090e34 Chris Moore committed Mar 14, 2012
Showing with 33 additions and 6 deletions.
  1. +1 −0 Procfile
  2. +8 −6 config.ru
  3. +24 −0 rack_try_static.rb
View
@@ -0,0 +1 @@
+web: bundle exec middleman build && thin start --port $PORT
View
@@ -1,11 +1,13 @@
-require 'rack'
-require 'rack/contrib/try_static'
-require "rack/contrib/static_cache"
+# encoding: utf-8
+
+require File.expand_path("../rack_try_static", __FILE__)
use ::Rack::TryStatic,
- :root => "build", # where middleman files are generated
- :urls => %w[/], # match all requests
- :try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially
+ :root => "build",
+ :urls => ["/"],
+ :try => [".html", "index.html", "/index.html"]
+
+run lambda { [404, {"Content-Type" => "text/plain"}, ["File not found!"]] }
# Cache static assets
use Rack::StaticCache, :urls => ['/'], :root => 'build'
View
@@ -0,0 +1,24 @@
+# encoding: utf-8
+
+module Rack
+ class TryStatic
+ def initialize(app, options)
+ @app = app
+ @try = ["", *options.delete(:try)]
+ @static = ::Rack::Static.new(
+ lambda { [404, {}, []] },
+ options)
+ end
+
+ def call(env)
+ orig_path = env["PATH_INFO"]
+ found = nil
+ @try.each do |path|
+ resp = @static.call(env.merge!({"PATH_INFO" => orig_path + path}))
+ break if 404 != resp[0] && found = resp
+ end
+ found or @app.call
+ end
+ end
+end
+

0 comments on commit 5239296

Please sign in to comment.