Sha256: d128d869850c6fb4e5e1117bcbbad9af2071da83b799527eba4c333dc10db5b9

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

require "rack/mime"
require "mini_mime"

class Jets::PublicController < Jets::Controller::Base
  layout false

  def show
    catchall = params[:catchall].blank? ? 'index.html' : params[:catchall]
    public_path = Jets.root + "public"
    catchall_path = "#{public_path}/#{catchall}"

    if File.exist?(catchall_path)
      content_type = Rack::Mime.mime_type(File.extname(catchall_path))
      binary = !MiniMime.lookup_by_filename(catchall_path).content_type.include?("text")

      # For binary support to work, the client also has to send the right Accept header.
      # And the media type has been to added to api gateway.
      # Cavaet: adding * to as the media type breaks regular form submission.
      # All form submission gets treated as binary.
      if binary
        encoded_content = Base64.encode64(IO.read(catchall_path))
        render plain: encoded_content, content_type: content_type, base64: true
      else
        render file: catchall_path, content_type: content_type
      end
    else
      not_found_path = "#{public_path}/404.html"
      if File.exist?(not_found_path)
        render file: not_found_path, status: 404
      else
        render plain: "404 Not Found", status: 404
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jets-5.0.13 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.12 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.11 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.10 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.9 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.8 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.7 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.6 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.5 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.4 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.3 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.2 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.1 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.0 engines/internal/app/controllers/jets/public_controller.rb
jets-5.0.0.beta1 engines/internal/app/controllers/jets/public_controller.rb