Sha256: 92e42b7bcb684a493c4d09104b6f894b129dde99cd68ae51a632e8bdca13fdf9

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

module DiscoApp
  module AppProxyController
    extend ActiveSupport::Concern

    included do
      before_action :verify_proxy_signature
      before_action :shopify_shop
      after_action :add_liquid_header

      rescue_from ActiveRecord::RecordNotFound do |exception|
        render_error 404
      end
    end

    private

      def verify_proxy_signature
        unless proxy_signature_is_valid?
          head :unauthorized
        end
      end

      def proxy_signature_is_valid?
        return true if DiscoApp.configuration.skip_proxy_verification?
        DiscoApp::ProxyService.proxy_signature_is_valid?(request.query_string, ShopifyApp.configuration.secret)
      end

      def shopify_shop
        @shop = Shop.find_by_shopify_domain!(params[:shop])
      end

      def add_liquid_header
        response.headers['Content-Type'] = 'application/liquid'
      end

      def render_error(status)
        add_liquid_header
        render "disco_app/proxy_errors/#{status}", status: status
      end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
disco_app-0.8.4 app/controllers/disco_app/app_proxy_controller.rb
disco_app-0.8.5 app/controllers/disco_app/app_proxy_controller.rb