質問

Unicornでテストしたい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>

私はここで何が欠けているのか本当に理解していません:(

何か案が ?

よろしくお願いします、

luc

役に立ちましたか?

解決

この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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top