Skip to content

Instantly share code, notes, and snippets.

@dacamo76
Forked from wjlroe/Gemfile
Last active December 12, 2015 01:38
Show Gist options
  • Save dacamo76/4692004 to your computer and use it in GitHub Desktop.
Save dacamo76/4692004 to your computer and use it in GitHub Desktop.
Example running webmachine-ruby on Heroku

webmachine-ruby with Unicorn on Heroku

A very basic webmachine-ruby example app running with Unicorn/Rack on Heroku

Once the Heroku toolbelt is installed in your development environment, run the following:

$ bundle install
$ foreman start
10:14:22 web.1  | started with pid 50172
10:14:23 web.1  | I, [2013-02-01T10:14:23.144259 #50172]  INFO -- : listening on addr=0.0.0.0:5000 fd=11
10:14:23 web.1  | I, [2013-02-01T10:14:23.144360 #50172]  INFO -- : worker=0 spawning...
10:14:23 web.1  | I, [2013-02-01T10:14:23.145088 #50172]  INFO -- : master process ready
10:14:23 web.1  | I, [2013-02-01T10:14:23.145844 #50173]  INFO -- : worker=0 spawned pid=50173
10:14:23 web.1  | I, [2013-02-01T10:14:23.146181 #50173]  INFO -- : Refreshing Gem list
10:14:23 web.1  | I, [2013-02-01T10:14:23.242999 #50173]  INFO -- : worker=0 ready

You should see "hi" on localhost:5000 (or whatever port your app was started on)

To deploy to heroku:

$ heroku create
$ git push heroku master

That's it!

require 'webmachine/adapter'
require 'webmachine/adapters/rack'
require File.join(File.dirname(__FILE__), 'my_rest_app')
run App.adapter
module MyRESTApp
module Resources
class Echo < Webmachine::Resource
def to_html
if @request.query.has_key?("ping")
return "<p>PONG</p>"
else
return "<p>Hi. <a href=\"/?ping=me\">ping me</a></p>"
end
end
end
end
end
source :rubygems
gem 'webmachine'
gem 'unicorn'
GEM
remote: http://rubygems.org/
specs:
i18n (0.6.1)
kgio (2.8.0)
multi_json (1.5.0)
rack (1.5.1)
raindrops (0.10.0)
unicorn (4.5.0)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
webmachine (1.1.0)
i18n (>= 0.4.0)
multi_json
PLATFORMS
ruby
DEPENDENCIES
unicorn
webmachine
require 'webmachine'
require File.join(File.dirname(__FILE__), 'echo_resource')
App = Webmachine::Application.new do |app|
app.configure do |config|
config.adapter = :Rack
end
app.routes do
add ['*'], MyRESTApp::Resources::Echo
end
end
web: bundle exec unicorn -p $PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment