Update CORS settings, enhance API URL detection, and improve template rendering
- Added new CORS origins for local development and specific IP addresses in `settings.py`. - Refactored API URL retrieval logic in `loadSiteDefinition.ts` and `fileAccess.ts` to auto-detect based on the current origin. - Enhanced error handling in API calls and improved logging for better debugging. - Updated `renderTemplate` function to support additional block types and improved rendering logic for various components in `templateEngine.tsx`.
This commit is contained in:
@@ -7,7 +7,30 @@
|
||||
*/
|
||||
|
||||
const SITES_DATA_PATH = import.meta.env.SITES_DATA_PATH || '/sites';
|
||||
const API_URL = import.meta.env.VITE_API_URL || 'https://api.igny8.com/api';
|
||||
|
||||
/**
|
||||
* Get API base URL - auto-detect based on current origin
|
||||
*/
|
||||
function getApiBaseUrl(): string {
|
||||
const envUrl = import.meta.env.VITE_API_URL;
|
||||
if (envUrl) {
|
||||
return envUrl.endsWith('/api') ? envUrl : `${envUrl}/api`;
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
const origin = window.location.origin;
|
||||
if (/^\d+\.\d+\.\d+\.\d+/.test(origin) || origin.includes('localhost') || origin.includes('127.0.0.1')) {
|
||||
if (origin.includes(':8024')) {
|
||||
return origin.replace(':8024', ':8011') + '/api';
|
||||
}
|
||||
return origin.split(':')[0] + ':8011/api';
|
||||
}
|
||||
}
|
||||
|
||||
return 'https://api.igny8.com/api';
|
||||
}
|
||||
|
||||
const API_URL = getApiBaseUrl();
|
||||
|
||||
/**
|
||||
* Get file URL for a site asset.
|
||||
|
||||
Reference in New Issue
Block a user