1414 * limitations under the License.
1515 */
1616
17- import { API_STATUS_CODES , FALLBACK_REQUEST_TIMEOUT , Host } from '@Common/Constants'
17+ import { API_STATUS_CODES , FALLBACK_REQUEST_TIMEOUT , Host , SERVICE_PATHS } from '@Common/Constants'
1818import { noop } from '@Common/Helper'
1919import { ServerErrors } from '@Common/ServerError'
2020import { APIOptions , ResponseType } from '@Common/Types'
@@ -40,6 +40,30 @@ class CoreAPI {
4040 this . handleRedirectToLicenseActivation = handleRedirectToLicenseActivation || noop
4141 }
4242
43+ /**
44+ * Constructs the final URL by detecting service paths and applying appropriate routing
45+ * @param url - The endpoint URL
46+ * @returns The final URL with correct base path
47+ */
48+ private constructUrl = ( url : string ) : string => {
49+ // Check if URL starts with a known service path
50+ const isServicePath = Object . values ( SERVICE_PATHS ) . some (
51+ ( servicePath ) => url . startsWith ( `${ servicePath } /` ) || url . startsWith ( `/${ servicePath } /` ) ,
52+ )
53+
54+ // Check if it's a non-orchestrator service path
55+ const isNonOrchestratorService =
56+ isServicePath && ! url . startsWith ( 'orchestrator/' ) && ! url . startsWith ( '/orchestrator/' )
57+
58+ if ( isNonOrchestratorService ) {
59+ // For service paths like 'athena/', use as-is but ensure single leading slash
60+ return url . startsWith ( '/' ) ? url : `/${ url } `
61+ }
62+ // For orchestrator paths or relative paths, add Host prefix
63+ const cleanUrl = url . startsWith ( '/' ) ? url . slice ( 1 ) : url
64+ return `${ this . host } /${ cleanUrl } `
65+ }
66+
4367 private fetchAPI = async < K = object > ( {
4468 url,
4569 type,
@@ -54,11 +78,14 @@ class CoreAPI {
5478 method : type ,
5579 signal,
5680 body : data ? JSON . stringify ( data ) : undefined ,
81+ headers : {
82+ 'Content-Type' : 'application/json' ,
83+ } ,
5784 }
5885 // eslint-disable-next-line dot-notation
5986 options [ 'credentials' ] = 'include' as RequestCredentials
6087 return fetch (
61- ` ${ this . host } / ${ url } ` ,
88+ this . constructUrl ( url ) ,
6289 ! isMultipartRequest
6390 ? options
6491 : ( {
0 commit comments