Browse files

Use TryStatic in config.ru to serve html files in public, too

  • Loading branch information...
1 parent 0ab56cb commit 7dbbf93c4c250dba471492cd2bbb0efc3561f0ad @jlong committed Feb 23, 2013
Showing with 8 additions and 1 deletion.
  1. +3 −0 lib/serve/bootstrap/Gemfile
  2. +5 −1 lib/serve/bootstrap/config.ru
View
3 lib/serve/bootstrap/Gemfile
@@ -2,6 +2,9 @@ source 'https://rubygems.org'
gem 'serve', '#{Serve.version}'
+# TryStatic
+gem 'rack-contrib'
+
# Use edge instead:
# gem 'serve', :git => 'git://github.com/jlong/serve.git'
View
6 lib/serve/bootstrap/config.ru
@@ -39,9 +39,13 @@ if ENV['SERVER_SOFTWARE'] =~ /passenger/i
# Passenger only needs the adapter
run Serve::RackAdapter.new(root + '/views')
else
+ # Use Rack::TryStatic to attempt to load files from public first
+ require 'rack/contrib/try_static'
+ use Rack::TryStatic, :root => (root + '/public'), :urls => %w(/), :try => %w(.html index.html /index.html)
+
# Use Rack::Cascade and Rack::Directory on other platforms for static assets
run Rack::Cascade.new([
Serve::RackAdapter.new(root + '/views'),
Rack::Directory.new(root + '/public')
])
-end
+end

0 comments on commit 7dbbf93

Please sign in to comment.