ugh
This commit is contained in:
@@ -29,10 +29,18 @@ export const apiRequest = async <T = any>(endpoint: string, method: string = "GE
|
||||
options.body = JSON.stringify(body);
|
||||
}
|
||||
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
if (!API_URL) throw new Error("NEXT_PUBLIC_API_URL is not set in environment variables");
|
||||
// Always use the Next.js API proxy to ensure all requests go through rewrites
|
||||
// Format the endpoint to ensure it has the /api prefix
|
||||
let url;
|
||||
if (endpoint.startsWith('/api/')) {
|
||||
url = endpoint; // Already has /api/ prefix
|
||||
} else {
|
||||
// Add /api prefix and ensure no duplicate slashes
|
||||
const cleanEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
||||
url = `/api${cleanEndpoint}`;
|
||||
}
|
||||
|
||||
const res = await fetchData(`${API_URL}${endpoint}`, options);
|
||||
const res = await fetchData(url, options);
|
||||
|
||||
if (!res) {
|
||||
const errorResponse = await res.json().catch(() => null);
|
||||
|
||||
Reference in New Issue
Block a user