feat: update environment configuration, enhance Dockerfiles, and refactor API handling

This commit is contained in:
2025-09-07 19:55:49 +02:00
parent 5f8cf49ec9
commit 08213133be
14 changed files with 53 additions and 56 deletions

View File

@@ -111,7 +111,10 @@ export type ApiKey = z.infer<typeof ApiKeySchema>;
export type ApiKeyResponse = z.infer<typeof ApiKeyResponseSchema>;
export type ThoughtThread = z.infer<typeof ThoughtThreadSchema>;
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000";
const API_BASE_URL =
typeof window === "undefined"
? process.env.NEXT_PUBLIC_SERVER_SIDE_API_URL // Server-side
: process.env.NEXT_PUBLIC_API_URL; // Client-side
async function apiFetch<T>(
endpoint: string,
@@ -119,6 +122,10 @@ async function apiFetch<T>(
schema: z.ZodType<T>,
token?: string | null
): Promise<T> {
if (!API_BASE_URL) {
throw new Error("API_BASE_URL is not defined");
}
const headers: Record<string, string> = {
"Content-Type": "application/json",
...(options.headers as Record<string, string>),
@@ -128,7 +135,8 @@ async function apiFetch<T>(
headers["Authorization"] = `Bearer ${token}`;
}
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
const fullUrl = `${API_BASE_URL}${endpoint}`;
const response = await fetch(fullUrl, {
...options,
headers,
});