From 4b7f3f554be2b8bab5fbe6674995b419862ebfa0 Mon Sep 17 00:00:00 2001 From: Daniel S Date: Mon, 10 Aug 2026 00:16:41 +0200 Subject: [PATCH] fix: add automatic draft compilation fallback in loader and explicit API error logging --- app/data/site.config.json | 36 +++++++++++++++++- app/data/waas.db | Bin 32768 -> 32768 bytes src/pages/api/editor/add-section.ts | 1 + src/pages/api/editor/delete-section.ts | 1 + .../api/editor/update-section-settings.ts | 1 + src/pages/api/editor/update-section.ts | 1 + src/utils/configLoader.ts | 25 +++++++++++- 7 files changed, 63 insertions(+), 2 deletions(-) diff --git a/app/data/site.config.json b/app/data/site.config.json index d225c69..a9ab874 100644 --- a/app/data/site.config.json +++ b/app/data/site.config.json @@ -52,9 +52,43 @@ "title": "Bereit für Ihr Projekt?", "subtitle": "Schreiben Sie uns direkt. Wir antworten innerhalb von 24 Stunden persönlich." } + }, + { + "id": "sec_bentogrid_1786313652833", + "type": "BentoGrid", + "settings": { + "sectionTitle": "Unsere Highlights", + "sectionSubtitle": "Modernste Features im Überblick" + } + }, + { + "id": "sec_herosection_1786313653735", + "type": "HeroSection", + "settings": { + "title": "Neue Überschrift", + "subtitle": "Beschreibungstext hier eingeben.", + "ctaPrimaryText": "Jetzt anfragen", + "ctaPrimaryLink": "#contact" + } + }, + { + "id": "sec_contactsection_1786313654351", + "type": "ContactSection", + "settings": { + "title": "Kontaktieren Sie uns", + "subtitle": "Wir antworten innerhalb von 24 Stunden." + } + }, + { + "id": "sec_bentogrid_1786313698683", + "type": "BentoGrid", + "settings": { + "sectionTitle": "Unsere Highlights", + "sectionSubtitle": "Modernste Features im Überblick" + } } ] } ], - "updated_at": "2026-08-09T22:08:57.203Z" + "updated_at": "2026-08-09T22:16:29.073Z" } \ No newline at end of file diff --git a/app/data/waas.db b/app/data/waas.db index 947edab85efa80f6c86d1a58c2c9d8f446a5e42d..6fb3f4540d1232a5bf8859d7679a9d429a01d971 100644 GIT binary patch delta 1002 zcmZo@U}|V!njp={Gf~Ewk!NGVl6WC@_K6I9tUOP-H*+1~EaYflpSZEHnmx8Lhn>q= zUY@bhzR_N=I5jywDK)PoKfNe3CEn27!pzvv*v!(x%)+=JF+DXtBR@CQ2_)|hlxM3} z0;(^`%+CwSEXhe#vQi4oD^4v+Rq)76&&UDdlH$oWx$;(Ssfi_}MXALKnYjvw=Om>T zCFNu$XDihbr`-*w_S(igHZEUzO~yv^Msu*!lk@XR5|c}yu7bPY)Wq0y@|kQ2UDj%) z5~x$XK}xerGJ)>RQwYvXRVd9XR?<-_E=_`|n5>_prmqKbCQO7lJ@p_xwM_x6T<-G9 zj7{=Q@?f`Rq!#64ILz4G*c2YH9zYerkN{;tSn8KrnhFWF;^d5?%(N0zS30GFgi|w< zO7qf-OHwOJ6x1?+o>EB7%u7!NMx`E5d2&f&Kv8CHVo_xXPysNWyi!Z5CO^$H3Mbic zqRrNft8L6-A(XOAjVz3@q%3CQk_Lq-OA2?&+PpbCkVS}{-;;s=5&s5$PyP%1nf#yl z`!)+I81vW5GdnW^qY_t6VOL@H1 { return new Response(JSON.stringify({ success: true, section_id: secId }), { status: 201 }); } catch (error) { + console.error('[API /api/editor/add-section] Exception:', error); return new Response(JSON.stringify({ error: 'Fehler beim Hinzufügen der Sektion' }), { status: 500 }); } }; diff --git a/src/pages/api/editor/delete-section.ts b/src/pages/api/editor/delete-section.ts index 70b8046..43dd2b2 100644 --- a/src/pages/api/editor/delete-section.ts +++ b/src/pages/api/editor/delete-section.ts @@ -20,6 +20,7 @@ export const POST: APIRoute = async ({ request }) => { return new Response(JSON.stringify({ success: true, message: 'Sektion gelöscht' }), { status: 200 }); } catch (error) { + console.error('[API /api/editor/delete-section] Exception:', error); return new Response(JSON.stringify({ error: 'Fehler beim Löschen der Sektion' }), { status: 500 }); } }; diff --git a/src/pages/api/editor/update-section-settings.ts b/src/pages/api/editor/update-section-settings.ts index c57b7e9..01010a3 100644 --- a/src/pages/api/editor/update-section-settings.ts +++ b/src/pages/api/editor/update-section-settings.ts @@ -50,6 +50,7 @@ export const POST: APIRoute = async ({ request }) => { return new Response(JSON.stringify({ success: true, settings: { ...updatedDraft, ...updatedStyles } }), { status: 200 }); } catch (error) { + console.error('[API /api/editor/update-section-settings] Exception:', error); return new Response(JSON.stringify({ error: 'Fehler beim Aktualisieren der Sektions-Einstellungen' }), { status: 500 }); } }; diff --git a/src/pages/api/editor/update-section.ts b/src/pages/api/editor/update-section.ts index a9f1803..f92501c 100644 --- a/src/pages/api/editor/update-section.ts +++ b/src/pages/api/editor/update-section.ts @@ -28,6 +28,7 @@ export const POST: APIRoute = async ({ request }) => { { status: 200 } ); } catch (error) { + console.error('[API /api/editor/update-section] Exception:', error); return new Response(JSON.stringify({ error: 'Fehler beim Aktualisieren der Sektionen' }), { status: 500 }); } }; diff --git a/src/utils/configLoader.ts b/src/utils/configLoader.ts index 4bf0572..de0485d 100644 --- a/src/utils/configLoader.ts +++ b/src/utils/configLoader.ts @@ -1,6 +1,7 @@ import fs from 'fs'; import path from 'path'; import { detectDeviceType } from './deviceDetect'; +import { getDb } from '../db/index'; export interface UIComponent { id: string; // Eindeutige ID (z.B. uuid / timestamp) slotId: string; // Platz-ID (z.B. 'hero-badge-slot', 'hero-actions-slot', 'bento-slot-1') @@ -283,7 +284,29 @@ export function loadWaasConfigs(userAgent: string = '', isDraft: boolean = false const genericSitePath = path.join(dataDir, 'site.config.json'); let sitePath = genericSitePath; - if (isDraft && fs.existsSync(draftSitePath)) { + if (isDraft) { + if (!fs.existsSync(draftSitePath)) { + try { + const db = getDb(); + const settingsRow = db.prepare('SELECT value_json FROM site_settings WHERE key = ?').get('site_config') as { value_json: string } | undefined; + const baseConfig = settingsRow ? JSON.parse(settingsRow.value_json) : {}; + const pagesRows = db.prepare('SELECT * FROM pages ORDER BY created_at ASC').all() as any[]; + const pages = pagesRows.map((page) => { + const sectionsRows = db.prepare('SELECT * FROM page_sections WHERE page_id = ? ORDER BY order_index ASC').all(page.id) as any[]; + const sections = sectionsRows.map((sec) => ({ + id: sec.id, + type: sec.section_type, + settings: { ...JSON.parse(sec.content_draft_json || '{}'), ...JSON.parse(sec.styles_json || '{}') } + })); + return { id: page.id, slug: page.slug, title: page.title, is_published: page.status === 'published', sections }; + }); + const fullDraftConfig = { ...baseConfig, pages, updated_at: new Date().toISOString() }; + fs.mkdirSync(dataDir, { recursive: true }); + fs.writeFileSync(draftSitePath, JSON.stringify(fullDraftConfig, null, 2), 'utf-8'); + } catch (e) { + console.warn('[WaaS ConfigLoader] Fallback draft compilation warning:', e); + } + } sitePath = draftSitePath; } else if (fs.existsSync(deviceSitePath)) { sitePath = deviceSitePath;