Class: Routemaster::Middleware::RootPostOnly

Inherits:
Object
  • Object
show all
Defined in:
lib/routemaster/middleware/root_post_only.rb

Overview

Rejects all requests but POST to the root path

Instance Method Summary collapse

Constructor Details

#initialize(app, _options = {}) ⇒ RootPostOnly

Returns a new instance of RootPostOnly.



5
6
7
# File 'lib/routemaster/middleware/root_post_only.rb', line 5

def initialize(app, _options = {})
  @app  = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
# File 'lib/routemaster/middleware/root_post_only.rb', line 9

def call(env)
  return [404, {}, []] unless ['', '/'].include? env['PATH_INFO']
  return [405, {}, []] if env['REQUEST_METHOD'] != 'POST'
  @app.call(env)
end