@@ -17,7 +17,8 @@ def initialize(api_key, delivery_token, environment, options={})
1717 raise Contentstack ::Error . new ( "Envirnoment Field is not valid" ) if environment . class != String
1818 raise Contentstack ::Error . new ( "Envirnoment Field Should not be Empty" ) if environment . empty?
1919 @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
2122 @live_preview = !options . key? ( :live_preview ) ? { } : options [ :live_preview ]
2223 @branch = options [ :branch ] . nil? ? "" : options [ :branch ]
2324 @proxy_details = options [ :proxy ] . nil? ? "" : options [ :proxy ]
@@ -80,13 +81,43 @@ def sync(params)
8081
8182 private
8283 def get_default_region_hosts ( region = 'us' )
84+ host = "https://cdn.contentstack.io" #set default host if region is nil
8385 case region
8486 when "us"
8587 host = "https://cdn.contentstack.io"
8688 when "eu"
8789 host = "https://eu-cdn.contentstack.com"
90+ when "azure-na"
91+ host = "https://azure-na-cdn.contentstack.com"
92+ when "azure-eu"
93+ host = "https://azure-eu-cdn.contentstack.com"
8894 end
8995 host
9096 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+
91122 end
92123end
0 commit comments