Skip to content

Commit

Permalink
Rework the config.ru so that it will do redirects, even when testing …
Browse files Browse the repository at this point in the history
…locally. Only difference between heroku and here, should be the run command! we still want the other parts
  • Loading branch information
Hampton Catlin committed Oct 15, 2013
1 parent 301f2c9 commit bd3f172
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
require "rubygems"

if ENV["HEROKU"].nil? || ENV["HEROKU"] == 'false'
require "middleman"
run Middleman.server
else
require "rack/rewrite"
require "rack/rewrite"

use Rack::Rewrite do
r301 %r{/docs/yardoc/(.*)}, '/documentation/$1'
r301 '/tutorial.html', '/guide'
r301 '/download.html', '/install'
r301 '/documentation', '/documentation/'
r301 '/documentation/_index.html', '/documentation/'
use Rack::Rewrite do
r301 %r{/docs/yardoc/(.*)}, '/documentation/$1'
r301 '/tutorial.html', '/guide'
r301 '/download.html', '/install'
r301 '/documentation', '/documentation/'
r301 '/documentation/_index.html', '/documentation/'

moved_permanently '/try.html', 'http://www.sassmeister.com'
moved_permanently '/try.html', 'http://www.sassmeister.com'

rewrite(%r{^(.*)/([^/.]+)$}, lambda do |match, rack_env|
path = "#{File.dirname(__FILE__)}/build#{match[0]}"
next "#{match[1]}/#{match[2]}/index.html" if Dir.exists?(path)
next match[0] if File.exists?(path)
"#{match[0]}.html"
end)
end
rewrite(%r{^(.*)/([^/.]+)$}, lambda do |match, rack_env|
path = "#{File.dirname(__FILE__)}/build#{match[0]}"
next "#{match[1]}/#{match[2]}/index.html" if Dir.exists?(path)
next match[0] if File.exists?(path)
"#{match[0]}.html"
end)
end

if ENV["HEROKU"].nil? || ENV["HEROKU"] == 'false'
require "middleman"
run Middleman.server
else
use Rack::Static, :urls => [""], :root => 'build', :index => 'index.html'

run lambda {}
Expand Down

0 comments on commit bd3f172

Please sign in to comment.