MVChem
initial commit
01923e1
Raw History Blame Contribute Delete
597 Bytes
import type { Example, Project } from './types';
const isStatic = import.meta.env.VITE_STATIC_DATA === 'true';
async function read<T>(name: string, signal: AbortSignal): Promise<T> {
const url = isStatic ? `./api/${name}.json` : `/api/${name}`;
const response = await fetch(url, { signal });
if (!response.ok) throw new Error('Project content could not be loaded. Please try again.');
return response.json() as Promise<T>;
}
export const api = {
project: (signal: AbortSignal) => read<Project>('project', signal),
example: (signal: AbortSignal) => read<Example>('example', signal),
};