This commit is contained in:
NotII
2025-03-23 23:53:45 +00:00
parent edc220bc5d
commit 3413e3b1e8
8 changed files with 122 additions and 88 deletions

View File

@@ -14,15 +14,17 @@ export async function clientFetch(url: string, options: RequestInit = {}): Promi
...options.headers,
};
// Ensure the url doesn't start with a slash if it's going to be appended to a URL that ends with one
const cleanUrl = url.startsWith('/') ? url.substring(1) : url;
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '/api';
// Always use the Next.js API proxy for consistent routing
// Format the URL to ensure it has the /api prefix
let fullUrl;
if (url.startsWith('/api/')) {
fullUrl = url; // Already has /api/ prefix
} else {
// Add /api prefix if not already present
const cleanUrl = url.startsWith('/') ? url : `/${url}`;
fullUrl = `/api${cleanUrl}`;
}
// Ensure there's only one slash between the base URL and endpoint
const fullUrl = baseUrl.endsWith('/')
? `${baseUrl}${cleanUrl}`
: `${baseUrl}/${cleanUrl}`;
const res = await fetch(fullUrl, {
...options,
headers,