diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..94d0372 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# API Keys +GEMINI_API_KEY=your_api_key_here + +# API Configuration +API_BASE_URL=http://localhost:3000 +ENVIRONMENT=development diff --git a/client/src/lib/queryClient.ts b/client/src/lib/queryClient.ts index f315a14..79e1ab1 100644 --- a/client/src/lib/queryClient.ts +++ b/client/src/lib/queryClient.ts @@ -1,57 +1,33 @@ -import { QueryClient, QueryFunction } from "@tanstack/react-query"; +import { QueryClient } from '@tanstack/react-query'; -async function throwIfResNotOk(res: Response) { - if (!res.ok) { - const text = (await res.text()) || res.statusText; - throw new Error(`${res.status}: ${text}`); - } -} - -export async function apiRequest( +export async function apiRequest( method: string, url: string, data?: unknown | undefined, -): Promise { +): Promise { const res = await fetch(url, { method, - headers: data ? { "Content-Type": "application/json" } : {}, + headers: data ? { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${process.env.GEMINI_API_KEY}` + } : {}, body: data ? JSON.stringify(data) : undefined, - credentials: "include", + credentials: 'include', }); - await throwIfResNotOk(res); - return res; -} - -type UnauthorizedBehavior = "returnNull" | "throw"; -export const getQueryFn: (options: { - on401: UnauthorizedBehavior; -}) => QueryFunction = - ({ on401: unauthorizedBehavior }) => - async ({ queryKey }) => { - const res = await fetch(queryKey.join("/") as string, { - credentials: "include", - }); - - if (unauthorizedBehavior === "returnNull" && res.status === 401) { - return null; - } + if (!res.ok) { + const text = await res.text(); + throw new Error(`API Error ${res.status}: ${text || res.statusText}`); + } - await throwIfResNotOk(res); - return await res.json(); - }; + return res.json(); +} export const queryClient = new QueryClient({ defaultOptions: { queries: { - queryFn: getQueryFn({ on401: "throw" }), refetchInterval: false, refetchOnWindowFocus: false, - staleTime: Infinity, - retry: false, - }, - mutations: { - retry: false, }, }, }); diff --git a/server/config.ts b/server/config.ts new file mode 100644 index 0000000..1e70353 --- /dev/null +++ b/server/config.ts @@ -0,0 +1,9 @@ +export const CONFIG = { + API_KEYS: { + GEMINI_API_KEY: process.env.GEMINI_API_KEY, + }, + API_ENDPOINTS: { + TEXT_API: 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-09-2025:generateContent', + IMAGE_API: 'https://generativelanguage.googleapis.com/v1beta/models/imagen-3.0-generate-002:predict' + } +};