Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
added possibility to setup custom cjs path
Browse files Browse the repository at this point in the history
  • Loading branch information
bartes committed Jan 12, 2019
1 parent d2a2de8 commit ccc700b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/castle/middleware/body_modify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class BodyModify
extend Forwardable
def_delegators :@middleware, :log, :configuration

CJS_PATH = 'https://d2t77mnxyo7adj.cloudfront.net/v1/c.js'.freeze

def initialize
@middleware = Middleware.instance
end
Expand Down Expand Up @@ -48,7 +46,7 @@ def close_old_response(response)
def js_content_to_add(req)
[
"\n",
script_tag('', type: 'text/javascript', src: "#{CJS_PATH}?#{configuration.app_id}"),
script_tag('', type: 'text/javascript', src: "#{configuration.cjs_path}?#{configuration.app_id}"),
script_tag(js_commands(req).join, js_options(req)),
"\n"
].join
Expand Down
2 changes: 1 addition & 1 deletion lib/castle/middleware/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Configuration
def_delegators :@options,
:logger, :transport, :api_secret, :app_id,
:tracker_url, :autoforward_client_id, :cookie_domain,
:services, :api_options,
:services, :api_options, :cjs_path,
:events, :identify, :user_traits, :security_headers
def_delegators :@middleware, :log, :track

Expand Down
4 changes: 4 additions & 0 deletions lib/castle/middleware/configuration/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ class Middleware
# Configuration options accessible for configure in mounted app
class Configuration
class Options
CJS_PATH = 'https://d2t77mnxyo7adj.cloudfront.net/v1/c.js'.freeze

%i[
api_secret
api_options
cjs_path
app_id
tracker_url
autoforward_client_id
Expand All @@ -27,6 +30,7 @@ class Options
def initialize
@events = {}
@security_headers = false
@cjs_path = CJS_PATH
@api_options = {}
@identify = {}
@user_traits = {}
Expand Down
2 changes: 1 addition & 1 deletion spec/castle/middleware/sensor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def xhr?

matcher :inject_the_script do
match_unless_raises do |subscriber|
expect(subscriber[2]).to include ::Castle::Middleware::BodyModify::CJS_PATH
expect(subscriber[2]).to include ::Castle::Middleware::Configuration::Options::CJS_PATH
end
end

Expand Down

0 comments on commit ccc700b

Please sign in to comment.