Sha256: 136affef1a943eadc509142c4f06d5470679cf1297cf388d5b997450d4142859

Contents?: true

Size: 1.04 KB

Versions: 165

Compression:

Stored size: 1.04 KB

Contents

require "rack/mime"
require "mimemagic"

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

  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 = !MimeMagic.by_path(catchall_path).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
      render file: "#{public_path}/404", status: 404
    end
  end
end

Version data entries

165 entries across 165 versions & 3 rubygems

Version Path
jets-2.3.19 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-3.0.2 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-3.0.1 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-3.0.0 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.18 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.17 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.16 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.15 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.14 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.13 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.12 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.11 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.10 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.9 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.8 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.7 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.6 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.5 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.4 lib/jets/internal/app/controllers/jets/public_controller.rb
jets-2.3.3 lib/jets/internal/app/controllers/jets/public_controller.rb