@@ -68,9 +68,27 @@ export default function contentstackHttpClient (options) {
6868 config . basePath = `/${ config . basePath . split ( '/' ) . filter ( Boolean ) . join ( '/' ) } `
6969 }
7070 const baseURL = config . endpoint || `${ protocol } ://${ hostname } :${ port } ${ config . basePath } /{api-version}`
71- const region = config . region || 'na'
72- const uiHostName = getRegionEndpoint ( region , 'application' )
73- const developerHubBaseUrl = getRegionEndpoint ( region , 'developerHub' ) . replace ( / ^ / , 'https://' )
71+
72+ let region = config . region || 'na'
73+ if ( ! config . region && config . host ) {
74+ const hostRegionMatch = config . host . match ( / ^ ( [ a - z ] + - ? [ a - z ] * ) - a p i \. / )
75+ if ( hostRegionMatch ) {
76+ region = hostRegionMatch [ 1 ]
77+ }
78+ }
79+
80+ let uiHostName , developerHubBaseUrl
81+ if ( config . host && ( config . host . startsWith ( 'dev' ) || config . host . startsWith ( 'stag' ) ) ) {
82+ uiHostName = config . host . replace ( '-api.' , '-app.' )
83+ const transformedHost = config . host
84+ . replace ( / ^ d e v \d + / , 'dev' )
85+ . replace ( / ^ s t a g \d + / , 'stag' )
86+ developerHubBaseUrl = `https://${ transformedHost . replace ( '-api.' , '-developerhub-api.' ) } `
87+ } else {
88+ uiHostName = getRegionEndpoint ( region , 'application' )
89+ developerHubBaseUrl = `https://${ getRegionEndpoint ( region , 'developerHub' ) } `
90+ }
91+
7492 const uiBaseUrl = config . endpoint || `${ protocol } ://${ uiHostName } `
7593
7694 // set ui host name
0 commit comments