如何部署 Sinatra + Heroku 上的小胡子?

发布于 2024-12-27 17:52:39 字数 1582 浏览 3 评论 0原文

我在本地有一个非常基本的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔一刀 2025-01-03 17:52:39

每当您从 Sinatra::Base 继承时,您都必须在 顶部 require 'sinatra/base' 而不是 require 'sinatra' >web.rb 文件。

我刚刚使用您的代码片段运行了一个简单的测试,并且能够复制并通过这样做修复错误。

Whenever you inherit from Sinatra::Base you must require 'sinatra/base' rather than require 'sinatra' at the top of your web.rb file.

I just ran a simple test using your snippets and was able to replicate and then fix the error by doing this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文