|
@@ -4,9 +4,12 @@ import type {
|
|
|
KeyScope,
|
|
KeyScope,
|
|
|
} from '@/types'
|
|
} from '@/types'
|
|
|
import { ApiError } from '@/types'
|
|
import { ApiError } from '@/types'
|
|
|
|
|
+import { serverUrl } from '@/api/base'
|
|
|
|
|
|
|
|
async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
|
async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
|
|
- const res = await fetch(path, {
|
|
|
|
|
|
|
+ // `path` is server-absolute ('/api/v1/...'); serverUrl() adds the mount prefix
|
|
|
|
|
+ // so the same build works at '/' and under a subpath proxy like '/rag/'.
|
|
|
|
|
+ const res = await fetch(serverUrl(path), {
|
|
|
...options,
|
|
...options,
|
|
|
credentials: 'include',
|
|
credentials: 'include',
|
|
|
headers: { 'Content-Type': 'application/json', ...(options.headers || {}) },
|
|
headers: { 'Content-Type': 'application/json', ...(options.headers || {}) },
|
|
@@ -14,7 +17,8 @@ async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
|
|
if (res.status === 401 && !path.endsWith('/ui/login')) {
|
|
if (res.status === 401 && !path.endsWith('/ui/login')) {
|
|
|
const { useAuthStore } = await import('@/stores/authStore')
|
|
const { useAuthStore } = await import('@/stores/authStore')
|
|
|
useAuthStore.getState().reset()
|
|
useAuthStore.getState().reset()
|
|
|
- if (location.pathname !== '/login') location.assign('/login')
|
|
|
|
|
|
|
+ // Hash routing: the route lives in location.hash, not the path.
|
|
|
|
|
+ if (location.hash !== '#/login') location.hash = '#/login'
|
|
|
throw new ApiError(401, 'unauthorized')
|
|
throw new ApiError(401, 'unauthorized')
|
|
|
}
|
|
}
|
|
|
const text = await res.text()
|
|
const text = await res.text()
|