Sinatra(Ruby)中的静态页面路由 [英] Static page routing in Sinatra (Ruby)

查看:69
本文介绍了Sinatra(Ruby)中的静态页面路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以通过将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)中的静态页面路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆