Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Sinatra app on Heroku

I have simple Sinatra app.

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

But when I deploy my app on Heroku I'll get the error on logs:

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=

How can I fix it?

like image 769
ceth Avatar asked Mar 27 '12 19:03

ceth


People also ask

Is Heroku hosting free forever?

Free Services on Heroku Heroku offers a free plan to help you learn and get started on the platform. Heroku Buttons and Buildpacks are free, and many Heroku Add-ons also offer a free plan.

Is Heroku good for production apps?

Heroku is so easy to use that it's a top choice for many development projects. With a special focus on supporting customer-focused apps, it enables simple application development and deployment.


2 Answers

Here's how to create a minimal sinatra app that deploys to heroku:

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

Type these commands in your command line to deploy (without the $ signs):

$ bundle install
$ git init
$ git add -f app.rb Gemfile Gemfile.lock config.ru
$ git commit -am "initial commit"
$ heroku create <my-app-name>
$ git push heroku master

Then test your app:

$ curl <my-app-name>.heroku.com

and you should see:

hello world
like image 68
Patrick Oscity Avatar answered Oct 10 '22 17:10

Patrick Oscity


You need a Procfile file alongside your config.ru to tell Heroku how to run your app. Here is the content of an example Procfile:

web: bundle exec ruby web.rb -p $PORT

Heroku Ruby docs on Procfiles

EDIT: Here's a sample config.ru from one of my sinatra/Heroku apps:

$:.unshift File.expand_path("../", __FILE__)
require 'rubygems'
require 'sinatra'
require './web'
run Sinatra::Application

You may need to require sinatra and rubygems for it to work.

like image 45
Eric Wendelin Avatar answered Oct 10 '22 15:10

Eric Wendelin