Skip to content

Instantly share code, notes, and snippets.

@asaaki
Created March 8, 2012 00:15
Show Gist options
  • Save asaaki/1997494 to your computer and use it in GitHub Desktop.
Save asaaki/1997494 to your computer and use it in GitHub Desktop.
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
# ActionController::Metal, it follows the same structure of
# config/application.rb, config/environment.rb and config.ru
# existing in any Rails 3 app. Here they are simply in one
# file and without the comments.
require "rails"
require "rails/all"
class MyApp < Rails::Application
routes.append do
match "/hello/world" => "hello#world"
end
# Enable cache classes. Production style.
config.cache_classes = true
# Here you could remove some middlewares, for example
# Rack::Lock, AD::Flash and AD::BestStandardsSupport below.
# The remaining stack is printed on rackup (for fun!).
# Rails 4 will have config.middleware.api_only! to get
# rid of browser related middleware.
config.middleware.delete "Rack::Lock"
config.middleware.delete "ActionDispatch::Flash"
config.middleware.delete "ActionDispatch::BestStandardsSupport"
# We need a secret token for session, cookies, etc.
config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
end
# This is a barebone controller. One good reference can be found here:
# http://piotrsarnacki.com/2010/12/12/lightweight-controllers-with-rails3/
class HelloController < ActionController::Metal
include ActionController::Rendering
def world
render :text => "Hello world!"
end
end
# Initialize the app
MyApp.initialize!
# Print the stack for fun!
puts ">> Starting Rails lightweight stack"
Rails.configuration.middleware.each do |middleware|
puts "use #{middleware.inspect}"
end
puts "run #{Rails.application.class.name}.routes"
# Run it!
run MyApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment