问题描述
您可以通过将Sinatra静态文件放在 public /
(默认情况下)中来提供静态文件-我有一个 index.html
目前在那儿,但是如何在不将该文件解析为模板的情况下指向该文件的根点?
You can serve static files with Sinatra by placing them in public/
(by default) -- I have an index.html
in there at the moment, but how can I make the root point to that file without having to parse it as a template?
可以成功访问 /index.html
,并且我想将 /
路由为同一静态文件,但是无需重定向。知道如何执行此操作吗?
To be clear, I can access /index.html
successfully, and I'd like to route /
to be the same static file, but without redirecting. Any idea how to do this?
推荐答案
也许最终会有更好的答案,直到这是我的目标。
Probably a better answer will eventually come, until then this is my shot at it.
如果这不是您想要的:
get '/' do
redirect '/index.html'
end
您可能会做某事像这样:
You might do something like this:
get '/' do
File.new('public/index.html').readlines
end
我会和第一个一起去,不知道为什么要避免重定向
I'd go with the first one though, Not sure why you want to avoid that redirect
这篇关于Sinatra(Ruby)中的静态页面路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!