Sha256: db5f7b9b7ed0e9b252423b19934c99c077da063f4987d65bce2555ae4f9d16b8

Contents?: true

Size: 1.04 KB

Versions: 52

Compression:

Stored size: 1.04 KB

Contents

module Scrivito
  #
  # This module lets you change the URL of a binary CMS object for the purpose of
  # fetching the binary data from a different location (e.g. via a proxy or from a mirror).
  #
  #
  # @api public
  #
  module BinaryRewrite
    def self.call(request, url)
      change_url_callback = request.env["SCRIVITO_BINARY_URL_CALLBACK"]
      url = change_url_callback.call(url) if change_url_callback
      url
    end
    #
    # You can, for example, have the URLs of images, etc., point to your desired
    # domain instead of to the CDN Scrivito uses.
    #
    # @api public
    #
    # @param request [ActionDispatch::Request]
    # @param block [Proc] block change default CDN url of current binary obj
    #
    # @example
    #   Scrivito::BinaryRewrite.enable_for(request) do |binary_url|
    #     binary_url.sub(
    #       /https:\/\/.+\.scrvt\.com\//,
    #       "https://my.reverse.proxy.com/")
    #   end
    #
    def self.enable_for(request, &block)
      request.env["SCRIVITO_BINARY_URL_CALLBACK"] = block
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
scrivito_sdk-1.18.0 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.18.0.rc1 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.17.0 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.17.0.rc3 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.17.0.rc2 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.17.0.rc1 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.16.0 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.16.0.rc2 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.16.0.rc1 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.15.0 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.15.0.rc2 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.15.0.rc1 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.14.0 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.14.0.rc3 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.14.0.rc2 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.14.0.rc1 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.13.0 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.13.0.rc2 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.13.0.rc1 app/cms/scrivito/binary_rewrite.rb
scrivito_sdk-1.12.0 app/cms/scrivito/binary_rewrite.rb