【问题标题】:nanoc site tested with unicornnanoc 网站用独角兽测试
【发布时间】:2011-04-28 07:16:30
【问题描述】:

我有一个 nanoc 网站(所以,所有静态页面),我想用 unicorn 进行测试。 这背后的想法是在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"

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

当我运行 unicorn 时,我收到以下错误消息:

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

我真的不明白我在这里缺少什么:(

有什么想法吗?

感谢和问候,

卢克

【问题讨论】:

    标签: ruby rack unicorn nanoc


    【解决方案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)] }
    

    问候, 卢克

    【讨论】:

    • 不错!我也很好奇,为你的成功感到高兴。与此同时,我找到了this,并且至少对我很有帮助:)
    猜你喜欢
    • 2014-01-15
    • 2012-01-05
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 2014-08-19
    • 2013-01-10
    相关资源
    最近更新 更多