erm what the sigma

This commit is contained in:
NotII
2025-03-24 13:46:53 +00:00
parent f5b5608f9d
commit d3c61ef1de
2 changed files with 3 additions and 101 deletions

View File

@@ -1,43 +1,4 @@
/** /**
<<<<<<< Updated upstream
<<<<<<< Updated upstream
* API utilities for consistent request handling
*/
/**
* Normalizes a URL to ensure it passes through the Next.js API proxy
* This ensures all client-side requests go through the Next.js rewrites.
*
* @param url The endpoint URL to normalize
* @returns A normalized URL with proper /api prefix
*/
export function normalizeApiUrl(url: string): string {
if (url.startsWith('/api/')) {
return url; // Already has /api/ prefix
} else {
// Add /api prefix, handling any leading slashes
const cleanUrl = url.startsWith('/') ? url : `/${url}`;
return `/api${cleanUrl}`;
}
}
/**
* Constructs a server-side API URL for backend requests
* Used in Server Components and API routes to directly access the backend API
*
* @param endpoint The API endpoint path
* @returns A complete URL to the backend API
*/
export function getServerApiUrl(endpoint: string): string {
const apiUrl = process.env.SERVER_API_URL || 'https://internal-api.inboxi.ng/api';
const cleanEndpoint = endpoint.startsWith('/') ? endpoint.substring(1) : endpoint;
return apiUrl.endsWith('/')
? `${apiUrl}${cleanEndpoint}`
: `${apiUrl}/${cleanEndpoint}`;
=======
=======
>>>>>>> Stashed changes
* API utilities for client and server-side requests * API utilities for client and server-side requests
*/ */
@@ -74,67 +35,18 @@ export function getServerApiUrl(endpoint: string): string {
const normalizedEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`; const normalizedEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
return `${normalizedBaseUrl}${normalizedEndpoint}`; return `${normalizedBaseUrl}${normalizedEndpoint}`;
<<<<<<< Updated upstream
>>>>>>> Stashed changes
=======
>>>>>>> Stashed changes
} }
/** /**
* Get the authentication token from cookies or localStorage * Get the authentication token from cookies or localStorage
<<<<<<< Updated upstream
<<<<<<< Updated upstream
*/
export function getAuthToken(): string | null {
if (typeof document === 'undefined') return null; // Guard for SSR
=======
=======
>>>>>>> Stashed changes
* Only available in client-side code * Only available in client-side code
*/ */
export function getAuthToken(): string | null { export function getAuthToken(): string | null {
if (typeof document === 'undefined') return null; if (typeof document === 'undefined') return null;
<<<<<<< Updated upstream
>>>>>>> Stashed changes
=======
>>>>>>> Stashed changes
return document.cookie return document.cookie
.split('; ') .split('; ')
.find(row => row.startsWith('Authorization=')) .find(row => row.startsWith('Authorization='))
<<<<<<< Updated upstream
<<<<<<< Updated upstream
?.split('=')[1] || localStorage.getItem('Authorization');
}
/**
* Check if the user is logged in
*/
export function isAuthenticated(): boolean {
return !!getAuthToken();
}
/**
* Creates standard API request headers with authentication
*
* @param token Optional auth token (fetched automatically if not provided)
* @param customHeaders Additional headers to include
* @returns Headers object ready for fetch requests
*/
export function createApiHeaders(token?: string | null, customHeaders: Record<string, string> = {}): Headers {
const headers = new Headers({
'Content-Type': 'application/json',
...customHeaders
});
const authToken = token || getAuthToken();
if (authToken) {
headers.set('Authorization', `Bearer ${authToken}`);
}
=======
=======
>>>>>>> Stashed changes
?.split('=')[1] || ?.split('=')[1] ||
(typeof localStorage !== 'undefined' ? localStorage.getItem('Authorization') : null); (typeof localStorage !== 'undefined' ? localStorage.getItem('Authorization') : null);
} }
@@ -155,9 +67,5 @@ export function createApiHeaders(token: string | null = null, additionalHeaders:
headers.append('Authorization', `Bearer ${authToken}`); headers.append('Authorization', `Bearer ${authToken}`);
} }
<<<<<<< Updated upstream
>>>>>>> Stashed changes
=======
>>>>>>> Stashed changes
return headers; return headers;
} }

View File

@@ -23,22 +23,16 @@ const nextConfig = {
destination: 'https://internal-api.inboxi.ng/api/:path*', destination: 'https://internal-api.inboxi.ng/api/:path*',
}, },
]; ];
}, } ,
<<<<<<< Updated upstream
<<<<<<< Updated upstream
// Build optimization settings for slower CPUs // Build optimization settings for slower CPUs
experimental: { experimental: {
swcMinify: true, swcMinify: true,
turbotrace: { turbotrace: {
logLevel: 'error' logLevel: 'error'
} }
}, },
=======
>>>>>>> Stashed changes
=======
>>>>>>> Stashed changes
// Reduce memory usage during builds // Reduce memory usage during builds
onDemandEntries: { onDemandEntries: {
// Period (in ms) where the server will keep pages in the buffer // Period (in ms) where the server will keep pages in the buffer
maxInactiveAge: 15 * 1000, maxInactiveAge: 15 * 1000,
// Number of pages that should be kept simultaneously without being disposed // Number of pages that should be kept simultaneously without being disposed