如何部署 Sinatra + Heroku 上的小胡子?
我在本地有一个非常基本的 Sinatra 网站。我正在使用“rackup”,您可以在其中定义一个 config.ru
,如下所示:
require './web'
use Rack::ShowExceptions
run App.new
然后在终端中您可以运行“rackup”,并且启动 Web 服务器,一切都很好。
然而,当我将其部署到 heroku 时,我没有收到任何错误消息,但是,当我访问该网站时,它显示标准的“Sinatra 不知道这个小曲”错误。
这是我的 web.rb
的一个片段,以防它有帮助:
require 'sinatra'
require 'maruku'
require 'mustache/sinatra'
require 'nokogiri'
class App < Sinatra::Base
register Mustache::Sinatra
require './views/layout'
set :mustache, {
:views => './views/',
:templates => './templates/'
}
get '/' do
"FUUUUUUUUUUUUU"
end
- 编辑
查看 Heroku 日志,它看起来就像 sinatra 启动然后停止;它不会继续运行。那么当有人发出请求时,显然服务器会返回 404
2012-01-20T12:39:23+00:00 app[web.1]: == Sinatra/1.1.0 has taken the stage on 16662 for development with backup from Thin
2012-01-20T12:39:23+00:00 app[web.1]: >> Thin web server (v1.2.7 codename No Hup)
2012-01-20T12:39:23+00:00 app[web.1]: >> Maximum connections set to 1024
2012-01-20T12:39:23+00:00 app[web.1]: >> Listening on 0.0.0.0:16662, CTRL+C to stop
2012-01-20T12:39:23+00:00 app[web.1]: == Sinatra has ended his set (crowd applauds)
2012-01-20T12:39:23+00:00 app[web.1]:
2012-01-20T12:39:23+00:00 app[web.1]: >> Stopping ...
2012-01-20T12:39:23+00:00 heroku[web.1]: Process exited
2012-01-20T12:39:24+00:00 heroku[router]: GET young-river-2245.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=48ms status=404 bytes=409
I have a really basic Sinatra site working locally. I am using the "rackup" thing, where you define a config.ru
like this:
require './web'
use Rack::ShowExceptions
run App.new
And then in the terminal you can run 'rackup' and a web server is fired up and all is well.
However, when I deploy this to heroku I don't get any error messages, but, when I visit the site, it says the standard "Sinatra does not know this ditty" error.
Here is a snippet of my web.rb
in case it helps:
require 'sinatra'
require 'maruku'
require 'mustache/sinatra'
require 'nokogiri'
class App < Sinatra::Base
register Mustache::Sinatra
require './views/layout'
set :mustache, {
:views => './views/',
:templates => './templates/'
}
get '/' do
"FUUUUUUUUUUUUU"
end
- Edit
Looking at the heroku logs, it appears like sinatra starts and then stops; it doesn't keep running. Then when someone makes a request obviously the server returns a 404
2012-01-20T12:39:23+00:00 app[web.1]: == Sinatra/1.1.0 has taken the stage on 16662 for development with backup from Thin
2012-01-20T12:39:23+00:00 app[web.1]: >> Thin web server (v1.2.7 codename No Hup)
2012-01-20T12:39:23+00:00 app[web.1]: >> Maximum connections set to 1024
2012-01-20T12:39:23+00:00 app[web.1]: >> Listening on 0.0.0.0:16662, CTRL+C to stop
2012-01-20T12:39:23+00:00 app[web.1]: == Sinatra has ended his set (crowd applauds)
2012-01-20T12:39:23+00:00 app[web.1]:
2012-01-20T12:39:23+00:00 app[web.1]: >> Stopping ...
2012-01-20T12:39:23+00:00 heroku[web.1]: Process exited
2012-01-20T12:39:24+00:00 heroku[router]: GET young-river-2245.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=48ms status=404 bytes=409
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当您从
Sinatra::Base
继承时,您都必须在顶部
文件。require 'sinatra/base'
而不是require 'sinatra'
>web.rb我刚刚使用您的代码片段运行了一个简单的测试,并且能够复制并通过这样做修复错误。
Whenever you inherit from
Sinatra::Base
you mustrequire 'sinatra/base'
rather thanrequire 'sinatra'
at the top of yourweb.rb
file.I just ran a simple test using your snippets and was able to replicate and then fix the error by doing this.