Cursor Agent
commited on
Commit
·
39d06f7
1
Parent(s):
073aa17
Deploy viewer for DynamicIntelligence/humanoid-robots-training-dataset
Browse files- src/utils/apiHelpers.ts +6 -4
src/utils/apiHelpers.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
/**
|
| 2 |
* Helper functions for API calls
|
| 3 |
* Handles both server-side and client-side URL construction
|
|
|
|
|
|
|
|
|
|
| 4 |
*/
|
| 5 |
|
| 6 |
-
import { headers } from 'next/headers';
|
| 7 |
-
|
| 8 |
/**
|
| 9 |
* Get the base URL for API calls
|
| 10 |
* For server-side, we need absolute URLs
|
|
@@ -14,7 +15,8 @@ export async function getApiBaseUrl(): Promise<string> {
|
|
| 14 |
// Server-side: need absolute URL
|
| 15 |
if (typeof window === 'undefined') {
|
| 16 |
try {
|
| 17 |
-
//
|
|
|
|
| 18 |
const headersList = await headers();
|
| 19 |
const host = headersList.get('host');
|
| 20 |
const protocol = headersList.get('x-forwarded-proto') || 'https';
|
|
@@ -23,7 +25,7 @@ export async function getApiBaseUrl(): Promise<string> {
|
|
| 23 |
return `${protocol}://${host}`;
|
| 24 |
}
|
| 25 |
} catch (error) {
|
| 26 |
-
// headers() might not be available in all contexts
|
| 27 |
// Fall through to environment variables
|
| 28 |
}
|
| 29 |
|
|
|
|
| 1 |
/**
|
| 2 |
* Helper functions for API calls
|
| 3 |
* Handles both server-side and client-side URL construction
|
| 4 |
+
*
|
| 5 |
+
* IMPORTANT: We cannot import 'next/headers' at top level because it breaks client-side usage.
|
| 6 |
+
* We use dynamic import only when needed on server-side.
|
| 7 |
*/
|
| 8 |
|
|
|
|
|
|
|
| 9 |
/**
|
| 10 |
* Get the base URL for API calls
|
| 11 |
* For server-side, we need absolute URLs
|
|
|
|
| 15 |
// Server-side: need absolute URL
|
| 16 |
if (typeof window === 'undefined') {
|
| 17 |
try {
|
| 18 |
+
// Dynamically import headers only when server-side (avoids client-side import error)
|
| 19 |
+
const { headers } = await import('next/headers');
|
| 20 |
const headersList = await headers();
|
| 21 |
const host = headersList.get('host');
|
| 22 |
const protocol = headersList.get('x-forwarded-proto') || 'https';
|
|
|
|
| 25 |
return `${protocol}://${host}`;
|
| 26 |
}
|
| 27 |
} catch (error) {
|
| 28 |
+
// headers() might not be available in all contexts (e.g., during build)
|
| 29 |
// Fall through to environment variables
|
| 30 |
}
|
| 31 |
|