在Heroku上部署Sinatra应用程序
我有简单的Sinatra应用程序。
web.rb:
require 'sinatra' get '/' do "Hello" end
的Gemfile:*
source :rubygems gem 'sinatra', '1.1.0' gem 'thin', '1.2.7'
config.ru:
require './web' run Sinatra::Application
但是当我在Heroku上部署我的应用程序时,我会在日志中收到错误:
2012-03-27T19:17:48+00:00 heroku[router]: Error H14 (No web processes running) -> GET furious-waterfall-6586.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
我该如何解决?
你需要一个Procfile
文件和你的config.ru
一起告诉Heroku如何运行你的应用程序。 以下是示例Procfile
的内容:
web: bundle exec ruby web.rb -p $PORT
关于Procfiles的Heroku Ruby文档
编辑:这是我的一个sinatra / Heroku应用程序的示例config.ru
:
$:.unshift File.expand_path("../", __FILE__) require 'rubygems' require 'sinatra' require './web' run Sinatra::Application
您可能需要使用sinatra和rubygems才能工作。
以下是如何创建一个部署到heroku的最小sinatra应用程序:
app.rb:
require 'sinatra' get '/' do "hello world" end
的Gemfile:
source 'https://rubygems.org' gem 'heroku' gem 'sinatra' gem 'thin'
config.ru:
require './app' run Sinatra::Application
在命令行中键入这些命令以进行部署(不带$
符号):
$ bundle install $ git init $ git add -f app.rb Gemfile Gemfile.lock config.ru $ git commit -am "initial commit" $ heroku create $ git push heroku master
然后测试你的应用:
$ curl .heroku.com
你应该看到:
hello world
我过去曾多次遇到过这个问题,而这一切都是因为我没有包含我的config.ru文件,需要[app] .rb然后推送到Heroku。 即使我之后添加它并重新启动,Heroku也永远不会把它拿起来。
- 在Heroku的网站上销毁你的小应用程序( http://www.heroku.com )
-
然后从项目文件夹中删除远程
$ git remote rm heroku
-
然后重新创建应用程序
尝试重新启动heroku
heroku restart
这里更多讨论: 未知的heroku错误
通过将gem’heroku’添加到Gemfile中,我得到了它的工作。 不需要Procfile。
作为更新,这是我创建的稍微更小的应用程序,并确认在今天工作。 不需要瘦的gem,并且不需要Procfile来获得初始工作的应用程序。
的Gemfile
source 'https://rubygems.org' gem 'sinatra'
config.ru
require './app' run Sinatra::Application
注意:require行使用’./app’而不是’app’。
app.rb
require 'sinatra' get '/' do 'Hello, World! Find me in app.rb' end
如果要使用此模板,可以复制,捆绑和推送Git仓库。
$ git init $ git add . $ git commit -m "initial sinatra app" $ bundle $ git add Gemfile.lock $ git commit -m "bundle install" $ heroku create $ git push heroku master $ heroku open