Sha256: 7b48642f519dff9662f7cd03642bd0f94c81c7c6637a69a24fe95c4f9c8d4bb7

Contents?: true

Size: 813 Bytes

Versions: 1

Compression:

Stored size: 813 Bytes

Contents

# frozen_string_literal: true

module NextRails
  class StaticPagesController < ApplicationController
    STATIC_FILES_PATH = Rails.root.join("public").to_s

    def index
      send_file file_path, type: "text/html", disposition: "inline"
    rescue ActionController::ResourceNotFound
      send_file File.join(STATIC_FILES_PATH, "404.html"), type: "text/html", disposition: "inline", status: 404
    rescue StandardError => e
      Rails.logger.error "StaticPagesController (#{e.class}): #{e.message}"
      raise e
    end

    private

    def file_path
      path = params.require(:file_path)

      raise ActionController::ResourceNotFound, "Not Found" unless File.exist?(path)
      raise ActionController::RoutingError, "Forbidden" unless path.start_with?(STATIC_FILES_PATH)

      path
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
next_rails_scaffold-0.1.9 app/controllers/next_rails/static_pages_controller.rb