Class: Rack::NotFound

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman/apps/rack_contrib.rb

Overview

Rack::NotFound is a default endpoint. Optionally initialize with the path to a custom 404 page, to override the standard response body.

Examples:

Serve default 404 response:

run Rack::NotFound.new

Serve a custom 404 page:

run Rack::NotFound.new('path/to/your/404.html')

Constant Summary collapse

F =
::File

Instance Method Summary collapse

Constructor Details

#initialize(path = nil, content_type = 'text/html') ⇒ NotFound

Returns a new instance of NotFound.



62
63
64
65
66
67
68
69
70
71
# File 'lib/middleman/apps/rack_contrib.rb', line 62

def initialize(path = nil, content_type = 'text/html')
  if path.nil?
    @content = "Not found\n"
  else
    @content = F.read(path)
  end
  @length = @content.size.to_s

  @content_type = content_type
end

Instance Method Details

#call(env) ⇒ Object



73
74
75
# File 'lib/middleman/apps/rack_contrib.rb', line 73

def call(env)
  [404, {'Content-Type' => @content_type, 'Content-Length' => @length}, [@content]]
end