我有一个网页的网站只使用超文本标记语言,CSS和JavaScript。我想将应用程序部署到Heroku,但我找不到方法。我现在正在尝试让这个应用程序与Sinatra一起工作。
.
|-- application.css
|-- application.js
|-- index.html
|-- jquery.js
`-- myapp.rb
下面是myapp.rb
的内容。
require 'rubygems'
require 'sinatra'
get "/" do
# What should I write here to point to the `index.html`
end
发布于 2010-03-13 21:34:20
无需任何额外配置,Sinatra将为public
中的资产提供服务。对于空路由,您需要呈现索引文档。
require 'rubygems'
require 'sinatra'
get '/' do
File.read(File.join('public', 'index.html'))
end
路由应该返回一个String
,它将成为HTTP响应主体。File.read
打开一个文件,读取该文件,关闭该文件并返回一个String
。
发布于 2011-08-05 21:45:42
您可以使用send_file
帮助器来提供文件。
require 'sinatra'
get '/' do
send_file File.join(settings.public_folder, 'index.html')
end
这将从任何已配置为包含应用程序静态文件的目录中提供index.html
。
发布于 2012-04-11 18:44:28
您可以只从公用文件夹托管它们,它们不需要路由。
.
-- myapp.rb
`-- public
|-- application.css
|-- application.js
|-- index.html
`-- jquery.js
在myapp.rb中
set :public_folder, 'public'
get "/" do
redirect '/index.html'
end
链接到公共文件夹中的某个子文件夹
set :public_folder, 'public'
get "/" do
redirect '/subfolder/index.html'
end
./public中的所有内容都可以通过‘/ from /bla.html’进行访问
示例:
./public/stylesheets/screen.css
将可通过'/stylesheets/screen.css‘访问,不需要路由
https://stackoverflow.com/questions/2437390
复制相似问题