使用 Sinatra 提供静态文件 [英] Serving static files with Sinatra
问题描述
我有一个仅使用 HTML、CSS 和 JavaScript 的单页网站.我想将该应用程序部署到 Heroku,但找不到方法.我现在正在尝试使该应用与 Sinatra 配合使用.
<预><代码>.|-- 应用程序.css|-- application.js|-- index.html|-- jquery.js`-- myapp.rb以下是myapp.rb
的内容.
需要'rubygems'需要'sinatra'得到/"做# 我应该在这里写什么来指向`index.html`结尾
无需任何额外配置,Sinatra 将在 public
中提供资产.对于空路由,您需要渲染索引文档.
需要'rubygems'需要'sinatra'得到'/'做File.read(File.join('public', 'index.html'))结尾
路由应该返回一个 String
成为 HTTP 响应主体.File.read
打开一个文件,读取文件,关闭文件并返回一个 String
.
I have one page website only using HTML, CSS and JavaScript. I want to deploy the app to Heroku, but I cannot find a way to do it. I am now trying to make the app working with Sinatra.
.
|-- application.css
|-- application.js
|-- index.html
|-- jquery.js
`-- myapp.rb
And the following is the content of myapp.rb
.
require 'rubygems'
require 'sinatra'
get "/" do
# What should I write here to point to the `index.html`
end
Without any additional configuration, Sinatra will serve assets in public
. For the empty route, you'll want to render the index document.
require 'rubygems'
require 'sinatra'
get '/' do
File.read(File.join('public', 'index.html'))
end
Routes should return a String
which become the HTTP response body. File.read
opens a file, reads the file, closes the file and returns a String
.
这篇关于使用 Sinatra 提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!