Skip to content

Instantly share code, notes, and snippets.

@logankoester
Last active December 25, 2015 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logankoester/6916133 to your computer and use it in GitHub Desktop.
Save logankoester/6916133 to your computer and use it in GitHub Desktop.
Serving static nanoc output with Unicorn instead of WEBrick for faster development.
require 'rack/rewrite'
use Rack::Rewrite do
rewrite %r{/projects/(\w+)/}, '/projects/$1/index.html'
end
use Rack::Static,
:urls => [
'/fonts',
'/images',
'/projects',
'/javascripts',
'/stylesheets',
'/index.html'
],
:root => 'output'
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=0'
},
File.open('output/index.html', File::RDONLY)
]
}
source 'https://rubygems.org'
gem 'unicorn'
gem 'rack'
gem 'rack-rewrite'
@logankoester
Copy link
Author

Run unicorn in your project root instead of nanoc view.

@mindreframer
Copy link

hm.. nice idea. why do you need the rewrite middleware? it works for me with this silly config:

# match-all static server
use Rack::Static, :urls => [""], :root => 'output', :index => 'index.html'

# dummy proc, never executed
run lambda { |env| [ 200, {}, 'OK']}

thx for the idea!

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