Sto scrivendo una semplice app Rack statica. Controlla il codice config.ru di seguito:Rack: come si memorizza l'URL come variabile?
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
mi piacerebbe semplificare questa memorizzando l'URL, variabile e la creazione di una sezione della mappa che dice
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
Come posso impostare correttamente questo URL variabile?
che funziona, grazie –
Si noti che questo imposterà il Content-type a 'text/html' per qualsiasi file che trova, anche 'robots.txt' o ' favicon.ico'. Ma immagino che puoi sempre lasciare questa linea, e lasciare che il browser indovini. – rbp