Last active
          December 25, 2015 04:19 
        
      - 
      
 - 
        
Save logankoester/6916133 to your computer and use it in GitHub Desktop.  
    Serving static nanoc output with Unicorn instead of WEBrick for faster development.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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) | |
| ] | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | source 'https://rubygems.org' | |
| gem 'unicorn' | |
| gem 'rack' | |
| gem 'rack-rewrite' | 
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
  
            
Run
unicornin your project root instead ofnanoc view.