Refactor API URLs and add environment config example
Replaces hardcoded production API URLs with localhost defaults for local development in both server and client code. Updates Dockerfile to require API URLs via deployment environment variables. Improves ChatTable to use a batch endpoint for chats and unread counts, with backward compatibility. Adds an env.example file to document required environment variables. Updates next.config.mjs to use environment variables for backend API rewrites and image domains.
This commit is contained in:
@@ -249,17 +249,18 @@ export async function fetchClient<T>(
|
||||
// Ensure the endpoint starts with a slash
|
||||
const normalizedEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
||||
|
||||
// For the specific case of internal-api.inboxi.ng - remove duplicate /api
|
||||
// Handle API endpoint construction without exposing internal domains
|
||||
let url;
|
||||
if (apiUrl.includes('internal-api.inboxi.ng')) {
|
||||
// Special case for internal-api.inboxi.ng
|
||||
// Check if this is a proxied API call (relative URLs starting with /api)
|
||||
if (apiUrl === '/api' || apiUrl.startsWith('/api')) {
|
||||
// For proxied requests, use relative URLs
|
||||
if (normalizedEndpoint.startsWith('/api/')) {
|
||||
url = `${apiUrl}${normalizedEndpoint.substring(4)}`; // Remove the /api part
|
||||
url = normalizedEndpoint; // Use as-is for proxied requests
|
||||
} else {
|
||||
url = `${apiUrl}${normalizedEndpoint}`;
|
||||
url = `/api${normalizedEndpoint}`;
|
||||
}
|
||||
} else {
|
||||
// Normal case for other environments
|
||||
// For direct API calls, construct full URL
|
||||
url = `${apiUrl}${normalizedEndpoint}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user