14 lines
620 B
TypeScript
14 lines
620 B
TypeScript
const developmentApi = new URL(window.location.origin);
|
|
developmentApi.port = '2003';
|
|
export const API_BASE_URL =
|
|
import.meta.env.VITE_API_BASE_URL ||
|
|
(import.meta.env.PROD ? window.location.origin : developmentApi.origin);
|
|
|
|
/** Browser credentials are HttpOnly cookies, never bundled or stored access tokens. */
|
|
export async function apiFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
|
const response = await window.fetch(input, { ...init, credentials: 'include' });
|
|
if (response.status === 401) {
|
|
window.dispatchEvent(new Event('stock-bot-auth-required'));
|
|
}
|
|
return response;
|
|
}
|