diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-12-17 09:53:56 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-12-17 09:53:56 -0600 |
commit | 61a41154f7d50099da371e0d2f22fd25ab9113c2 (patch) | |
tree | 257314af12fd4b66473752159b14e288af9864ee /railties/lib/rails_generator/generators/components/metal | |
parent | 97a178bfa4d5101dca73ae931cc9c77385d8c97e (diff) | |
download | rails-61a41154f7d50099da371e0d2f22fd25ab9113c2.tar.gz rails-61a41154f7d50099da371e0d2f22fd25ab9113c2.tar.bz2 rails-61a41154f7d50099da371e0d2f22fd25ab9113c2.zip |
Make generated Metal bits a pure rack endpoint application (not middleware)
Instead of calling super to pass the request on, return a 404.
The modified app looks like this:
# app/metal/poller.rb
class Poller
def self.call(env)
if env["PATH_INFO"] =~ /^\/poller/
[200, {"Content-Type" => "text/html"}, "Hello, World!"]
else
[404, {"Content-Type" => "text/html"}, "Not Found"]
end
end
end
But you aren't locked in to just Rails:
# app/metal/api.rb
require 'sinatra'
Sinatra::Application.default_options.merge!(:run => false, :env => :production)
Api = Sinatra.application unless defined? Api
get '/interesting/new/ideas' do
'Hello Sinatra!'
end
Diffstat (limited to 'railties/lib/rails_generator/generators/components/metal')
-rw-r--r-- | railties/lib/rails_generator/generators/components/metal/templates/metal.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/railties/lib/rails_generator/generators/components/metal/templates/metal.rb b/railties/lib/rails_generator/generators/components/metal/templates/metal.rb index 39487263df..e94982b69a 100644 --- a/railties/lib/rails_generator/generators/components/metal/templates/metal.rb +++ b/railties/lib/rails_generator/generators/components/metal/templates/metal.rb @@ -1,12 +1,12 @@ # Allow the metal piece to run in isolation require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) -class <%= class_name %> < Rails::Rack::Metal - def call(env) +class <%= class_name %> + def self.call(env) if env["PATH_INFO"] =~ /^\/<%= file_name %>/ - [200, {"Content-Type" => "text/html"}, "Hello, World!"] + [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] else - super + [404, {"Content-Type" => "text/html"}, ["Not Found"]] end end end |