ugh
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user