Skip to content

Commit 18dbb55

Browse files
Merge pull request #451 from contentstack/development
Development
2 parents c678d46 + 9454724 commit 18dbb55

File tree

3 files changed

+2729
-494
lines changed

3 files changed

+2729
-494
lines changed

lib/contentstack.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ export function client (params = {}) {
164164
let defaultHostName = getRegionEndpoint('na')
165165

166166
if (params.region) {
167-
defaultHostName = getRegionEndpoint(params.region.toLowerCase())
167+
params.region = params.region.toLowerCase()
168+
defaultHostName = getRegionEndpoint(params.region)
168169
}
169170

170171
const defaultParameter = {

lib/core/contentstackHTTPClient.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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]*)-api\./)
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(/^dev\d+/, 'dev')
85+
.replace(/^stag\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

Comments
 (0)