feat: overhaul server automation, files editor, and CS2 setup workflows
This commit is contained in:
+16
-3
@@ -1,4 +1,9 @@
|
||||
const API_BASE = '/api';
|
||||
const RAW_API_BASE = (
|
||||
(import.meta.env.VITE_API_URL as string | undefined) ??
|
||||
(import.meta.env.VITE_API_BASE_URL as string | undefined) ??
|
||||
'/api'
|
||||
).trim();
|
||||
const API_BASE = (RAW_API_BASE || '/api').replace(/\/+$/, '');
|
||||
|
||||
interface RequestOptions extends RequestInit {
|
||||
params?: Record<string, string>;
|
||||
@@ -36,7 +41,11 @@ async function request<T>(path: string, options: RequestOptions = {}): Promise<T
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
|
||||
const res = await fetch(url, { ...fetchOptions, headers });
|
||||
const res = await fetch(url, {
|
||||
...fetchOptions,
|
||||
credentials: fetchOptions.credentials ?? 'include',
|
||||
headers,
|
||||
});
|
||||
|
||||
const shouldHandle401WithRefresh =
|
||||
res.status === 401 &&
|
||||
@@ -49,7 +58,11 @@ async function request<T>(path: string, options: RequestOptions = {}): Promise<T
|
||||
const refreshed = await refreshToken();
|
||||
if (refreshed) {
|
||||
headers['Authorization'] = `Bearer ${localStorage.getItem('access_token')}`;
|
||||
const retry = await fetch(url, { ...fetchOptions, headers });
|
||||
const retry = await fetch(url, {
|
||||
...fetchOptions,
|
||||
credentials: fetchOptions.credentials ?? 'include',
|
||||
headers,
|
||||
});
|
||||
if (!retry.ok) throw new ApiError(retry.status, await retry.json().catch(() => null));
|
||||
if (retry.status === 204) return undefined as T;
|
||||
return retry.json();
|
||||
|
||||
Reference in New Issue
Block a user