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://scrivito-public-cdn.s3-eu-west-1.amazonaws.com/", # "https://my.reverse.proxy.com/") # end # def self.enable_for(request, &block) request.env["SCRIVITO_BINARY_URL_CALLBACK"] = block end end end