Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: jlong/serve
base: master
...
head fork: jlong/serve
compare: try-static
  • 1 commit
  • 4 files changed
  • 4 commit comments
  • 1 contributor
Commits on Apr 13, 2012
Nathaniel Talbott ntalbott Use Rack::TryStatic for static public files.
Rack::TryStatic will attempt to load paths from public before
passing them on to serve.

Also has more graceful handling for the case of a missing compass
config file.
7d2e666
1  Gemfile
View
@@ -1,6 +1,7 @@
source :rubygems
gem 'rack', '~> 1.2'
+gem 'rack-contrib'
gem 'rack-test', '~> 0.5'
gem 'tilt', '~> 1.3'
gem 'activesupport', '~> 3.0'
3  Gemfile.lock
View
@@ -46,6 +46,8 @@ GEM
mutter (0.5.3)
polyglot (0.3.2)
rack (1.3.2)
+ rack-contrib (1.1.0)
+ rack (>= 0.9.1)
rack-test (0.6.1)
rack (>= 1.0)
radius (0.7.3)
@@ -88,6 +90,7 @@ DEPENDENCIES
less (~> 1.2.21)
maruku (~> 0.6.0)
rack (~> 1.2)
+ rack-contrib
rack-test (~> 0.5)
radius (~> 0.7.3)
rake (~> 0.9.0)
2  lib/serve/application.rb
View
@@ -267,7 +267,7 @@ def run_server
use Rack::ShowExceptions
run Rack::Cascade.new([
Serve::RackAdapter.new(root),
- Rack::Directory.new(root)
+ Rack::Directory.new(root),
])
end
begin
10 lib/serve/bootstrap/config.ru
View
@@ -12,6 +12,7 @@ end
require 'serve'
require 'serve/rack'
+require 'rack/contrib/try_static'
# The project root directory
root = ::File.dirname(__FILE__)
@@ -24,7 +25,8 @@ if ENV['RACK_ENV'] != 'production'
require 'sass/plugin/rack'
require 'compass'
- Compass.add_project_configuration(root + '/compass.config')
+ config_file = root + '/compass.config'
+ Compass.add_project_configuration(config_file) if File.exist?(config_file)
Compass.configure_sass_plugin!
use Sass::Plugin::Rack # Sass Middleware
@@ -39,9 +41,11 @@ 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
+ 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')
+ Rack::Directory.new(root + '/public'),
])
-end
+end

Showing you all comments on commits in this comparison.

John W. Long
Owner

Comma?

John W. Long
Owner

Is Rack::Directory still needed for directory indexes?

Nathaniel Talbott
Collaborator

Hashes and Arrays in Ruby accept a trailing comma; it's handy when you're adding and removing from a list regularly.

Nathaniel Talbott
Collaborator

I think so; I'll double-check.

Something went wrong with that request. Please try again.