Add Sites Renderer service to Docker Compose and implement public endpoint for site definitions
- Introduced `igny8_sites` service in `docker-compose.app.yml` for serving deployed public sites. - Updated `SitesRendererAdapter` to construct deployment URLs dynamically based on environment variables. - Added `SiteDefinitionView` to provide a public API endpoint for retrieving deployed site definitions. - Enhanced `loadSiteDefinition` function to prioritize API calls for site definitions over filesystem access. - Updated frontend to utilize the new API endpoint for loading site definitions.
This commit is contained in:
@@ -16,26 +16,30 @@ const SITES_DATA_PATH = import.meta.env.SITES_DATA_PATH || '/sites';
|
||||
* then falls back to API.
|
||||
*/
|
||||
export async function loadSiteDefinition(siteId: string): Promise<SiteDefinition> {
|
||||
// Try filesystem first (for deployed sites)
|
||||
// Try API endpoint for deployed site definition first
|
||||
try {
|
||||
const fsPath = `${SITES_DATA_PATH}/clients/${siteId}/latest/site.json`;
|
||||
const response = await fetch(fsPath);
|
||||
if (response.ok) {
|
||||
const definition = await response.json();
|
||||
return definition;
|
||||
const response = await axios.get(`${API_URL}/v1/publisher/sites/${siteId}/definition/`);
|
||||
if (response.data) {
|
||||
return response.data as SiteDefinition;
|
||||
}
|
||||
} catch (error) {
|
||||
// Filesystem load failed, try API
|
||||
console.warn('Failed to load from filesystem, trying API:', error);
|
||||
// API load failed, try blueprint endpoint as fallback
|
||||
console.warn('Failed to load deployed site definition, trying blueprint:', error);
|
||||
}
|
||||
|
||||
// Fallback to API
|
||||
// Fallback to blueprint API (for non-deployed sites)
|
||||
try {
|
||||
const response = await axios.get(`${API_URL}/v1/site-builder/blueprints/${siteId}/`);
|
||||
const blueprint = response.data;
|
||||
const response = await axios.get(`${API_URL}/v1/site-builder/blueprints/?site=${siteId}`);
|
||||
const blueprints = Array.isArray(response.data?.results) ? response.data.results :
|
||||
Array.isArray(response.data) ? response.data : [];
|
||||
|
||||
// Transform blueprint to site definition format
|
||||
return transformBlueprintToSiteDefinition(blueprint);
|
||||
if (blueprints.length > 0) {
|
||||
const blueprint = blueprints[0]; // Get latest blueprint
|
||||
// Transform blueprint to site definition format
|
||||
return transformBlueprintToSiteDefinition(blueprint);
|
||||
}
|
||||
|
||||
throw new Error(`No blueprint found for site ${siteId}`);
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
throw new Error(`Failed to load site: ${error.message}`);
|
||||
|
||||
Reference in New Issue
Block a user