diff --git a/lib/core/contentstackHTTPClient.js b/lib/core/contentstackHTTPClient.js index 9a3e2a68..adb09788 100644 --- a/lib/core/contentstackHTTPClient.js +++ b/lib/core/contentstackHTTPClient.js @@ -68,9 +68,27 @@ export default function contentstackHttpClient (options) { config.basePath = `/${config.basePath.split('/').filter(Boolean).join('/')}` } const baseURL = config.endpoint || `${protocol}://${hostname}:${port}${config.basePath}/{api-version}` - const region = config.region || 'na' - const uiHostName = getRegionEndpoint(region, 'application') - const developerHubBaseUrl = getRegionEndpoint(region, 'developerHub').replace(/^/, 'https://') + + let region = config.region || 'na' + if (!config.region && config.host) { + const hostRegionMatch = config.host.match(/^([a-z]+-?[a-z]*)-api\./) + if (hostRegionMatch) { + region = hostRegionMatch[1] + } + } + + let uiHostName, developerHubBaseUrl + if (config.host && (config.host.startsWith('dev') || config.host.startsWith('stag'))) { + uiHostName = config.host.replace('-api.', '-app.') + const transformedHost = config.host + .replace(/^dev\d+/, 'dev') + .replace(/^stag\d+/, 'stag') + developerHubBaseUrl = `https://${transformedHost.replace('-api.', '-developerhub-api.')}` + } else { + uiHostName = getRegionEndpoint(region, 'application') + developerHubBaseUrl = `https://${getRegionEndpoint(region, 'developerHub')}` + } + const uiBaseUrl = config.endpoint || `${protocol}://${uiHostName}` // set ui host name diff --git a/test/sanity-check/api/oauth-test.js b/test/sanity-check/api/oauth-test.js index 4f7677d4..c06dc556 100644 --- a/test/sanity-check/api/oauth-test.js +++ b/test/sanity-check/api/oauth-test.js @@ -21,12 +21,6 @@ const oauthClient = client.oauth({ redirectUri: process.env.REDIRECT_URI }) -// Override developerHubBaseUrl if DEV_HUB_HOST is provided -if (process.env.DEV_HUB_HOST) { - oauthClient.axiosInstance.defaults.developerHubBaseUrl = `https://${process.env.DEV_HUB_HOST}` - oauthClient.developerHubBaseUrl = `https://${process.env.DEV_HUB_HOST}` -} - describe('OAuth Authentication API Test', () => { it('should login with credentials', done => { client.login({ email: process.env.EMAIL, password: process.env.PASSWORD }, { include_orgs: true, include_orgs_roles: true, include_stack_roles: true, include_user_settings: true }).then((response) => {