Sha256: fd8ecb069c1e9623758e9b2d2397b6d6c0ec83a4889b0ab40aa4e82c83ff7708

Contents?: true

Size: 953 Bytes

Versions: 13

Compression:

Stored size: 953 Bytes

Contents

# typed: false
# frozen_string_literal: true

require "openapi_first"

module PlugApp
  module Middleware
    # frozen_string_literal: true

    # 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')

    class NotFound
      F = ::File

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

        @content_type = content_type
      end

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hephaestus-0.6.0 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.5.2 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.5.1 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.5.0 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.4.0 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.3.1 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.2.3 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.2.2 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.1.3 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.1.2 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.1.1 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.0.2 templates/app/lib/plug_app/middleware/not_found.rb
hephaestus-0.0.1 templates/app/lib/plug_app/middleware/not_found.rb