@@ -2,7 +2,7 @@ import axios from 'axios'
22import clonedeep from 'lodash/cloneDeep'
33import Qs from 'qs'
44import { ConcurrencyQueue } from './concurrency-queue'
5- import { getRegionEndpoint , isHost } from './Util'
5+ import { isHost } from './Util'
66
77export default function contentstackHttpClient ( options ) {
88 const defaultConfig = {
@@ -68,28 +68,24 @@ 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+ let uiHostName = hostname
72+ let developerHubBaseUrl = hostname
7173
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- }
74+ if ( uiHostName ?. endsWith ( 'io' ) ) {
75+ uiHostName = uiHostName . replace ( 'io' , 'com' )
7876 }
7977
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' ) } `
78+ if ( uiHostName ) {
79+ uiHostName = uiHostName . replace ( 'api' , 'app' )
9080 }
9181
9282 const uiBaseUrl = config . endpoint || `${ protocol } ://${ uiHostName } `
83+ developerHubBaseUrl = developerHubBaseUrl
84+ ?. replace ( 'api' , 'developerhub-api' )
85+ . replace ( / ^ d e v \d + / , 'dev' ) // Replaces any 'dev1', 'dev2', etc. with 'dev'
86+ . replace ( 'io' , 'com' )
87+ . replace ( / ^ h t t p / , '' ) // Removing `http` if already present
88+ . replace ( / ^ / , 'https://' ) // Adds 'https://' at the start if not already there
9389
9490 // set ui host name
9591 const axiosOptions = {
0 commit comments