Skip to content

Commit 98f957d

Browse files
committed
feat:new root for connecting athena apis
1 parent 973920b commit 98f957d

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/Common/API/CoreAPI.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
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'
1818
import { noop } from '@Common/Helper'
1919
import { ServerErrors } from '@Common/ServerError'
2020
import { 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
: ({

src/Common/Constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ import { CostBreakdownItemViewParamsType, CostBreakdownViewType } from '@PagesDe
2020
export const FALLBACK_REQUEST_TIMEOUT = 60000
2121
export const Host = window?.__ORCHESTRATOR_ROOT__ ?? '/orchestrator'
2222

23+
// Service path constants for API routing
24+
export const SERVICE_PATHS = {
25+
ATHENA: 'athena',
26+
ORCHESTRATOR: 'orchestrator',
27+
// Add other service paths as needed in the future
28+
} as const
29+
2330
export const DOCUMENTATION_HOME_PAGE = 'https://docs.devtron.ai'
2431
export const DEVTRON_HOME_PAGE = 'https://devtron.ai/'
2532
export const DOCUMENTATION_VERSION = '/devtron/v1.7'

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ declare global {
194194
interface Window {
195195
__BASE_URL__: string
196196
__ORCHESTRATOR_ROOT__: string
197+
__ATHENA_ROOT__: string
197198
_env_: customEnv
198199
}
199200
}

0 commit comments

Comments
 (0)