2010-10-20 97 views
3

我有一个nanoc网站(所以,所有静态网页),我想与独角兽测试。 这个背后的想法是在heroku上托管这个网站。 该结构是一个机架应用程序。 我已经加入像config.ru文件:nanoc网站测试与独角兽

require 'rubygems' 
require 'rack' 
require 'rack-rewrite' 
require 'rack/contrib' 
use Rack::Rewrite do 
rewrite '/','/output/index.html' 
end 
use Rack::Static, :urls => ['/'], :root => "output" 

(我所有的静态资源位于输出目录)

当我运行的麒麟,我得到了以下错误消息:

NoMethodError at /output/index.html 
undefined method `to_i' for #<Rack::Static:0x10165ee18> 

我真的不明白我在这里失踪:(

任何想法?

感谢和问候,

吕克

回答

1

与此config.ru,它的工作原理:)

require 'rubygems' 
require 'rack' 
require 'rack/contrib' 
require 'rack-rewrite' 
require 'mime/types' 

use Rack::Deflater 
use Rack::ETag 
module ::Rack 
    class TryStatic < Static 

     def initialize(app, options) 
      super 
      @try = ([''] + Array(options.delete(:try)) + ['']) 
     end 

     def call(env) 
      @next = 0 
      while @next < @try.size && 404 == (resp = super(try_next(env)))[0] 
       @next += 1 
      end 
      404 == resp[0] ? @app.call : resp 
     end 

     private 
     def try_next(env) 
      env.merge('PATH_INFO' => env['PATH_INFO'] + @try[@next]) 
     end 
    end 
end 

use Rack::TryStatic, 
    :root => "output", # static files root dir 
    :urls => %w[/], # match all requests 
    :try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially 

errorFile='output/404.html' 
run lambda { [404, { 
      "Last-Modified" => File.mtime(errorFile).httpdate, 
      "Content-Type" => "text/html", 
      "Content-Length" => File.size(errorFile).to_s 
     }, File.read(errorFile)] } 

问候, 吕克

+0

不错!我也很好奇,为你的成功感到高兴。同时,我发现[这](http://teachmetocode.com/screencasts/faking-sinatra-with-rack-and-metaprogramming/)是有益的,对我来说至少:) – kfl62 2010-10-21 21:26:00

+0

你好,这是一段代码我在网上找到。感谢您的链接! – Luc 2010-10-21 21:38:48