nanoc网站用独角兽测试

时间:2010-10-20 21:30:13

标签: ruby rack unicorn nanoc

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

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 个答案:

答案 0 :(得分: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)] }

此致 LUC