Browse Source

fix: base url correction

pull/7444/head
Pranav C 10 months ago
parent
commit
f1d850a8c1
  1. 13
      packages/nc-gui/composables/useApi/index.ts
  2. 4
      packages/nc-gui/composables/useApi/interceptors.ts

13
packages/nc-gui/composables/useApi/index.ts

@ -6,14 +6,17 @@ import { addAxiosInterceptors } from './interceptors'
import { BASE_FALLBACK_URL, createEventHook, extractSdkResponseErrorMsg, ref, unref, useCounter, useNuxtApp } from '#imports' import { BASE_FALLBACK_URL, createEventHook, extractSdkResponseErrorMsg, ref, unref, useCounter, useNuxtApp } from '#imports'
export function createApiInstance<SecurityDataType = any>({ export function createApiInstance<SecurityDataType = any>({
baseURL = BASE_FALLBACK_URL, baseURL: _baseUrl = BASE_FALLBACK_URL,
}: CreateApiOptions = {}): Api<SecurityDataType> { }: CreateApiOptions = {}): Api<SecurityDataType> {
const config = useRuntimeConfig() const config = useRuntimeConfig()
const baseURL = config.public.ncBackendUrl || _baseUrl
return addAxiosInterceptors( return addAxiosInterceptors(
new Api<SecurityDataType>({ new Api<SecurityDataType>(
baseURL: config.public.ncBackendUrl || baseURL, {
}), baseURL,
},
baseUrl,
),
) )
} }

4
packages/nc-gui/composables/useApi/interceptors.ts

@ -5,7 +5,7 @@ const DbNotFoundMsg = 'Database config not found'
let refreshTokenPromise: Promise<string> | null = null let refreshTokenPromise: Promise<string> | null = null
export function addAxiosInterceptors(api: Api<any>) { export function addAxiosInterceptors(api: Api<any>, baseURL?: string) {
const state = useGlobal() const state = useGlobal()
const router = useRouter() const router = useRouter()
const route = router.currentRoute const route = router.currentRoute
@ -99,7 +99,7 @@ export function addAxiosInterceptors(api: Api<any>) {
return api.instance return api.instance
.post('/auth/token/refresh', null, { .post('/auth/token/refresh', null, {
withCredentials: true, withCredentials: true,
baseURL: location.pathname, baseURL: baseURL ?? './',
}) })
.then((token) => { .then((token) => {
// New request with new token // New request with new token

Loading…
Cancel
Save