Last active
July 4, 2024 17:24
-
-
Save umhan35/5127356 to your computer and use it in GitHub Desktop.
lightweight Ruby on Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Resource: http://www.scottraymond.net/2006/6/23/minimal-rails/ | |
# | |
# Run this file with: | |
# | |
# sh run.sh | |
# | |
# And access: | |
# | |
# http://localhost:3000/hello/world | |
# | |
# We are using Bundler in this example, but we could also | |
# have used rubygems: | |
# | |
# require "rubygems" | |
# | |
# gem "actionpack" | |
# gem "railties" | |
# | |
# require "rails" | |
# require "rails/all" | |
require "rails" | |
class MyApp < Rails::Application | |
# routes | |
routes.append do | |
get "/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/ | |
require "action_controller/railtie" | |
class HelloController < ActionController::Metal | |
include ActionController::Rendering | |
def world | |
render :text => "Hello world!" | |
end | |
end | |
# Initialize the app (originally in config/environment.rb) | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
# We are not loading Active Record, nor Active Resources etc. | |
# We can do this in any app by simply replacing the rails gem | |
# by the parts we want to use. | |
gem "actionpack" | |
gem "railties" | |
gem "tzinfo" | |
# Let's use thin | |
gem "thin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RAILS_ENV='4fun' bundle exec rackup -p 3000 -s thin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment