File size: 597 Bytes
01923e1
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
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),
};