在我的公共(public)文件夹中,我有一个文件index.html。我希望能够仅使用 url localhost:4567 来显示页面(不显示 localhost:4567/index.html)
这是我当前的 ruby 脚本:
require 'sinatra'
set :public_folder, 'public'
get '/' do
redirect '/index.html'
end
我已尝试删除重定向语句,但网址仍然出现 index.html。
最佳答案
您可以使用send_file
这里:
get "/" do
send_file 'public/index.html'
end
您需要提供工作目录中文件的完整路径(即不仅仅是 public
下的路径),并且这只适用于根 url,它不会提供 index.html
通常用于目录页面。如果您愿意,您可能需要在 Sinatra 前面设置一个单独的 Web 服务器并对其进行适当的配置。
关于ruby - 西纳特拉静态页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42140490/