ugh
This commit is contained in:
@@ -27,24 +27,16 @@ export async function fetchClient<T>(
|
||||
): Promise<T> {
|
||||
const { method = 'GET', body, headers = {}, ...rest } = options;
|
||||
|
||||
// Get the base API URL from environment or fallback
|
||||
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001';
|
||||
|
||||
// Ensure the endpoint starts with a slash
|
||||
// Always use the Next.js API proxy by creating a path starting with /api/
|
||||
// This ensures requests go through Next.js rewrites
|
||||
const normalizedEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
||||
|
||||
// For the specific case of internal-api.inboxi.ng - remove duplicate /api
|
||||
// Construct the URL to always use the Next.js API routes
|
||||
let url;
|
||||
if (apiUrl.includes('internal-api.inboxi.ng')) {
|
||||
// Special case for internal-api.inboxi.ng
|
||||
if (normalizedEndpoint.startsWith('/api/')) {
|
||||
url = `${apiUrl}${normalizedEndpoint.substring(4)}`; // Remove the /api part
|
||||
} else {
|
||||
url = `${apiUrl}${normalizedEndpoint}`;
|
||||
}
|
||||
if (normalizedEndpoint.startsWith('/api/')) {
|
||||
url = normalizedEndpoint; // Already has /api/ prefix
|
||||
} else {
|
||||
// Normal case for other environments
|
||||
url = `${apiUrl}${normalizedEndpoint}`;
|
||||
url = `/api${normalizedEndpoint}`; // Add /api/ prefix
|
||||
}
|
||||
|
||||
// Get auth token from cookies
|
||||
|
||||
Reference in New Issue
Block a user