2013-06-19 79 views
2

我使用Ruby Rack(https://devcenter.heroku.com/articles/static-sites-ruby)遵循了有關部署靜態文件的Heroku指南,但我無法訪問除index.html之外的\public中的任何HTML文件。即,localhost:9292/test.html仍然映射到index.html。 (所有我的風格和js文件都可以正常使用)。Ruby Rack Heroku:提供靜態文件

以下是我的config.ru文件。我知道什麼是錯,但不知道有效的解決方案?

use Rack::Static, :urls => ["/images", "/js", "/css"], :root => "public" 

run lambda { |env| [ 
    200, 
    { 
     'Content-Type' => 'text/html', 
     'Cache-Control' => 'public, max-age=86400' 
    }, 
    File.open('public/index.html', File::RDONLY) ] } 

回答

3

爲了您config.ru文件,請嘗試:

use Rack::Static, 
    :urls => ["/images", "/js", "/css"], 
    :root => "public" 

run Rack::File.new("public") 

你也可以用run Rack::Directory.new("public")替換最後一行這將成爲您的所有文件,但會給出一個文件瀏覽器一樣的界面,如果有人去一個目錄的URL(如根目錄)

0

我沒有Ruby的經驗,我發現這個樣板項目有用時試圖部署一個靜態網站到Heroku:

heroku-static-site

特別是,確保你也有GemfileGemfile.lock文件除了config.ru

作者的項目結構承載根目錄的一切,但你可以很容易的一切移動到public/和糾正config.ru爲@looby建議。