我正在编写一个简单的静态 Rack 应用程序。查看下面的 config.ru 代码:
use Rack::Static,
:urls => ["/elements", "/img", "/pages", "/users", "/css", "/js"],
:root => "archive"
map '/' do
run Proc.new { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=6400'
},
File.open('archive/splash.html', File::RDONLY)
]
}
end
map '/pages/search.html' do
run Proc.new { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=6400'
},
File.open('archive/pages/search.html', File::RDONLY)
]
}
end
map '/pages/user.html' do
run Proc.new { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=6400'
},
File.open('archive/pages/user.html', File::RDONLY)
]
}
end
# Each map section is repeated for each HTML page served
我想通过将 URL 存储为变量并创建一个地图部分来简化这一点
map url do
run Proc.new { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=6400'
},
File.open('archive' + url, File::RDONLY)
]
}
end
如何正确设置此 url 变量?