1

我的config.ru

require 'rack'
use Rack::Static, :root => '_site'

但是当我运行时rackup出现错误

/usr/local/share/gems/gems/rack-1.5.2/lib/rack/builder.rb:133:in `to_app': 缺少运行或映射语句 (RuntimeError)

我想_site_在根 URL的文件夹中托管文件

4

2 回答 2

3

Rack::Static是一个使用的中间件Rack::File,它是一个应用程序。如果您所做的只是提供静态文件,您可以直接运行Rack::File

# note 'run' not 'use'
run Rack::File.new('_site')
于 2013-09-29T12:43:30.760 回答
1

你的问题config.ru是它缺少一个run命令,而你总是需要一个。正如马特建议的那样,您可以使用Rack::File中间件。

但是,如果您想保留这些Rack::Static功能,那么您可以执行类似的操作来提供索引文件并Rack::Static在其前面放置中间件,以提供来自_site_.

use Rack::Static,
  :urls => ["/"],
  :root => "_site_"

run lambda { |env|
  [
    200,
    {
      'Content-Type'  => 'text/html',
      'Cache-Control' => 'public, max-age=86400'
    },
    File.open('public/index.html', File::RDONLY)
  ]
}
于 2020-10-06T04:14:57.390 回答