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:
NotII
2025-09-01 15:35:10 +01:00
parent 3528ca45cc
commit 29ec1be68c
8 changed files with 74 additions and 29 deletions

View File

@@ -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}`;
}

View File

@@ -21,7 +21,7 @@ try {
* @returns A complete URL to the backend API
*/
function getServerApiUrl(endpoint: string): string {
const apiUrl = process.env.SERVER_API_URL || 'https://internal-api.inboxi.ng/api';
const apiUrl = process.env.SERVER_API_URL || 'http://localhost:3001/api';
const cleanEndpoint = endpoint.startsWith('/') ? endpoint.substring(1) : endpoint;
return apiUrl.endsWith('/')