@@ -17,7 +17,8 @@ def initialize(api_key, delivery_token, environment, options={})
17
17
raise Contentstack ::Error . new ( "Envirnoment Field is not valid" ) if environment . class != String
18
18
raise Contentstack ::Error . new ( "Envirnoment Field Should not be Empty" ) if environment . empty?
19
19
@region = options [ :region ] . nil? ? Contentstack ::Region ::US : options [ :region ]
20
- @host = options [ :host ] . nil? ? get_default_region_hosts ( @region ) : options [ :host ]
20
+ # @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host] #removed for not supporting custom host with regions
21
+ @host = get_host_by_region ( @region , options ) # Added new method for custom host support with different regions
21
22
@live_preview = !options . key? ( :live_preview ) ? { } : options [ :live_preview ]
22
23
@branch = options [ :branch ] . nil? ? "" : options [ :branch ]
23
24
@proxy_details = options [ :proxy ] . nil? ? "" : options [ :proxy ]
@@ -80,7 +81,7 @@ def sync(params)
80
81
81
82
private
82
83
def get_default_region_hosts ( region = 'us' )
83
- host = "https://cdn.contentstack.io"
84
+ host = "https://cdn.contentstack.io" #set default host if region is nil
84
85
case region
85
86
when "us"
86
87
host = "https://cdn.contentstack.io"
@@ -93,5 +94,30 @@ def get_default_region_hosts(region='us')
93
94
end
94
95
host
95
96
end
97
+
98
+ def get_host_by_region ( region , options )
99
+ if options [ :host ] . nil? && region . present?
100
+ host = get_default_region_hosts ( region )
101
+ elsif options [ :host ] . present? && region . present?
102
+ custom_host = options [ :host ]
103
+ case region
104
+ when "us"
105
+ host = "https://cdn.#{ custom_host } "
106
+ when "eu"
107
+ host = "https://eu-cdn.#{ custom_host } "
108
+ when "azure-na"
109
+ host = "https://azure-na-cdn.#{ custom_host } "
110
+ when "azure-eu"
111
+ host = "https://azure-eu-cdn.#{ custom_host } "
112
+ end
113
+ elsif options [ :host ] . present? && region . empty?
114
+ custom_host = options [ :host ]
115
+ host = "https://cdn.#{ custom_host } "
116
+ else
117
+ host = "https://cdn.contentstack.io" #set default host if region and host is empty
118
+ end
119
+ host
120
+ end
121
+
96
122
end
97
123
end
0 commit comments