Class: BridgetownPluginNano::Middleware::NotFound

Inherits:
Object
  • Object
show all
Defined in:
lib/bridgetown-plugin-nano/rack_middleware/not_found.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, path, content_type = "text/html; charset=utf-8") ⇒ NotFound

Returns a new instance of NotFound.



6
7
8
9
10
11
# File 'lib/bridgetown-plugin-nano/rack_middleware/not_found.rb', line 6

def initialize(app, path, content_type = "text/html; charset=utf-8")
  @app = app
  @content = File.read(path)
  @length = @content.bytesize.to_s
  @content_type = content_type
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/bridgetown-plugin-nano/rack_middleware/not_found.rb', line 13

def call(env)
  response = @app.call(env)
  if response[0] == 404
    [404, { "Content-Type" => @content_type, "Content-Length" => @length }, [@content]]
  else
    response
  end
end